Tuesday, February 17, 2009

MySQL replication and slave errors

Sometimes, when there is connection problems, you run into situations, where data synchronization gets delayed and queries clash.

In such case, the mysql slave stops replicating until the issue is resolved.

Ideally, you would either reimport all your data from the master or resolve the issue manually. However sometimes that is not practical. In such a case, you have two easy ways to resume the replication process, ignoring the errors.

From mysql, you can issue these commands:

set global sql_slave_skip_counter = 1;
start slave;


Alternatively, you can ignore all errors in the future with this command line option:
--slave-skip-errors=1062,1053 (ignores duplicate primary key errors - you can specify other errors you want to ignore)

Friday, January 18, 2008

Logitech USB headset under linux

- compile the snd_usb_audio module (in devices -> audio -> usb)
- install the module: cd /usr/src/linux && make modules_install
- restart alsa: /etc/init.d/alsasound restart
- load the module: modproble snd_usb_audio
- make sure alsa has recognized the device: cat /proc/asoud/cards
- check sound levels (make sure it's not muted): alsamixer -c 1
- Test - play stuff with mplayer: mplayer -ao alsa:device=hw=1

Congratulations, you should be able to use your headphones now :)
Make sure you have the right number for alsamixer and mplayer (if your headset is your only device, the number would probably be 0)

Thursday, December 06, 2007

This is a not so well known method of embedding images in the HTML file itself. It allows you to include the images and HTML as a single file.

Advantages:

  • one file
  • easier migration
  • less error prone (encoding, binary type during transfer, etc)
  • Less HTTP requests (sometimes faster browser download)

Disadvantages

  • bigger HTML files
  • images not cached for subsequent loading

Here is what the image tag looks like:

<img src="data:image/png;base64,XXX64bit encoded binary dataXXX" />

You can use the following PHP code to generate that tag:
<?php
$fp = fopen('pic.png', 'rb');
$pic = fread($fp, filesize('pic.png'));
fclose($fp);
$base64 = chunk_split(base64_encode($pic));
echo '<img src="data:image/png;base64,'.$base64.'" />';

?>

A nifty trick, that comes very useful in some cases.

Thursday, November 22, 2007

Effordless synchronization via SSH

Setup SSH to authenticate via certificate

Generate key
ssh-keygen -t dsa

Copy public key to remote server
scp ~/.ssh/id_dsa.pub $REMOTE_HOST:.ssh/authorized_keys2

or if you already have keys in your key chain on the remote server
cat ~/.ssh/id_dsa.pub | ssh $REMOTE_HOST 'sh -c "cat - >>~/.ssh/authorized_keys2"'

Copy Files

Using rsync to copy files
rsync --archive --compress --itemize-changes --progress --exclude=.svn  $PATH $REMOTE_HOST:$PATH

Backing up databases

Using mysqldump to get schema and data
mysqldump --compact --compress --add-drop-table --delayed-insert --extended-insert --quick --quote-names --create-options --no-create-db --no-create-info --database $DB > /tmp/$DB.dump
scp /tmp/$DB.dump $RHOST:/tmp/$DB.dump
ssh $REMOTE_HOST "mysql -u root -p$PASSWORD < /tmp/$DB.dump"
rm /tmp/$DB.dump
ssh $REMOTE_HOST "rm /tmp/$DB.dump"

or (if allowed)
mysqldump --compact --compress --add-drop-table --delayed-insert --extended-insert --quick --quote-names --create-options --no-create-db --no-create-info --database $DB > mysql -u root -p$PASSWORD -h $REMOTE_HOST

Monday, August 21, 2006

Thursday, March 16, 2006

enabling mysql queries cache

edit my.cnf
in the mysqld section:
query-cache-type = 1
query-cache-size = 20M

restart mysql server

To check that it's working:
mysql -e "SHOW STATUS LIKE '%qcache%';"

Wednesday, December 21, 2005

PHP Profiling

Some useful information about how to profile php.
google groups thread

Admittedly, I didn't think of looking for this earlier, and I've been doing my own profiling by using microtime() between different sections of my code, but it looks like the methods mentioned above would work much, much better :)