Tips: Hacking MySQL Server

Hacking the latest storage engine? Working on a fancy new SHOW command? Hunting for a bug in mysqld? This is for you!

Once you’ve got MySQL compiled, how do you test your mysqld binary? You’ll need to get it started. Stop! Don’t make install it!

  1. Set up your sandbox
    $ mkdir ~/t
    $ vi ~/t/my.cnf
    

    Add the following to ~/t/my.cnf (modify to taste):

    [mysqld]
    basedir=.
    datadir=/Users/jcole/t 
    port=3307
    socket=/Users/jcole/t/mysql.sock
    skip-grant
    skip-innodb
    skip-bdb
    
    [client]
    port=3307
    socket=/Users/jcole/t/mysql.sock
    
  2. Build your source
  3. Set up a symlink for share/mysql pointing to the share directory.
    $ mkdir share && ln -s ../sql/share share/mysql
    

    This, combined with the basedir=. in my.cnf means that MySQL will be able to find its error message and character set files, so that the release you’re building doesn’t have to match the release installed on the system.

  4. Start mysqld
    $ sql/mysqld --defaults-file=~/t/my.cnf
    
  5. Start a mysql client (in another window)
    $ client/mysql --defaults-file=~/t/my.cnf
    
  6. Shutdown the mysqld (if it didn’t crash :) )
    $ client/mysqladmin --defaults-file=~/t/my.cnf shutdown
    

That’s it! Much easier, safer, and faster than using make install, and you don’t need to remember all the options to specify to start and test your newly built mysqld! If you manage to break your sandbox, just delete everything except my.cnf and you are back to a clean slate.

One thought on “Tips: Hacking MySQL Server

  1. DbRunas.com.ar - JCOLE: Tips: Hacking MySQL Server

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s