Archive for February, 2010

Dumping InnoDB tables without causing the slave to fall behind

Sunday, February 28th, 2010

Use a combination of non-locking table arguments for mysqdlump and the “nice” command to give mysqldump lower priority over other processes.

bash# nice -n 19 mysqldump --single-transaction --quick -uroot -p app3 > app3.2010022801.sql

–single-transaction doesn’t lock the tables when they are being dumped (by default -lock-tables would be enabled)

nice is a Unix command to tweak the priority of a process, from -20 (highest priority) to 19 (lowest priority)

You also probably want to compress the file to speed up transfer across the network to a backup server:

bash# tar -czvf app3.2010011801.sql.tar.gz app3.2010011801.sql

Using nice on complex queries that would actually eat up all the CPU works for every SQL query, not only mysqldump.
If you have such a complex query, instead of trying to run it from inside a mysql shell, run it from the bash as follows:

bash# nice -n 19 mysql -e "use mydb; select * from purchase where id in (select id from users where sex='female');"

… and compare with running it directly from the mysql prompt.

This is particularly handy for complex queries using JOINs between big tables.

Working ‘Become a fan’ button directly in Facebook apps

Saturday, February 6th, 2010

Until recently you could only put up a link to the application page and hope people would find the ‘Become a fan’ at the top button themselves.

Facebook was not providing a working button the way the ‘Add Bookmark’ button works.

Here’s the indirect way to do it, using Facebook Connect:

<fb:iframe scrolling="no" frameborder="0"
   allowtransparency="true" style="border: 0px solid #cccccc; width: 113px; height: 25px; ">

And your fan.css file should look like this:

.profileimage {
    display: none !important;

.name_block {
    display: none !important;

div {
    margin: 0px !important;
    padding: 0px !important;

The CSS is here to hide the app profile picture. If you want the picture to be displayed then just don’t use the CSS.


Timing your scripts

Monday, February 1st, 2010
$start_time = microtime(true);
<...insert code to time here...>
$stop_time = microtime(true);
$time_diff = $stop_time - $start_time;
echo "Script took $time_diff seconds to execute";