Tuesday, January 11, 2011

Using FileMerge with Mercurial

Mac OS comes with a GUI merge tool called FileMerge. This can be used for merges in Mercurial - Mercurial will do this if its internal merge fails. The binary for FileMerge (opendiff) cannot be used as is, so we need to create a small shell script. You can put this script anywhere in your path, and call it hopendiff:

`/usr/bin/opendiff "$@"`

Then modify your ~/.hgrc and add:

hgext.extdiff =

cmd.opendiff = hopendiff

filemerge.executable = hopendiff
filemerge.args = $local $other -ancestor $base -merge $output 

If you already have some of those sections (like [extensions]), then just add the corresponding lines to those sections.

That's it. When you do a merge in Mercurial, it'll open FileMerge if the internal merge fails. You can also use FileMerge for normal diffs by using hg opendiff instead of hg diff.

Thursday, January 6, 2011

Binary and character set safe MySQL dump and restore

To dump some MySQL databases in a binary-safe way:

mysqldump -uroot -p -hdbhost \ 
  --skip-extended-insert \ 
  --default-character-set=binary \ 
  --databases dbone dbtwo dbthree \ 
  --add-drop-database --master-data=2 | gzip > /tmp/dump.sql.gz

Replace --master-data=2 with --lock-all-tables if dumping from a slave, and record the output of SHOW SLAVE STATUS while everything is locked.

To import this dump:

zcat /tmp/dump.sql.gz | mysql -uroot -p -hotherdbhost \ 
   --unbuffered --batch --default-character-set=binary

To set up replication:

Use the Relay_Master_Log_File:Exec_Master_Log_Pos values from SHOW SLAVE STATUS that you recorded. See this page for explanation:


For example:

CHANGE MASTER TO MASTER_HOST = 'abc123.dklfjalddkj.com',
  MASTER_LOG_FILE = 'abc123-bin.003292',
  MASTER_LOG_POS = 283072761;