Running a second MySQL-instance on the same Linux box

Submitted by HighKing on Tue, 12/03/2013 - 14:58

Sometimes it can be useful to be able to start a second mysqld-instance on the same machine, for example when you need to restore some innodb-tables but only have a file back-up available of the MySQL-instance on the machine.

When searching the Internet, many people offer solutions for this that use a chroot. Well... I don't like to build-up a whole chroot just to run a second MySQL-daemon! ;-)

The solution? Simple: just run mysqld_safe with the '--no-defaults' switch so your daemon won't pick-up my.cnf. Use the '--port' and '--socket' switch to use a different port and socket and use the '--datadir' switch to tell mysqld where to find the restored databases. In full:

/usr/bin/mysqld_safe --no-defaults --port=3307 --socket=/tmp/mysql3307.sock --datadir=/tmp/restore &

Note that for this to work, the '--no-defaults' switch has to be the first switch(!).

This took me a while to find so I'll guess it's worth blogging about. Hope this saves someone else a headache. :-)