While preparing for the yesterday's MySQL/MariaDB 5.5 talk at the Mail.Ru technical forum, I downloaded the source code of three 5.5 forks - Oracle, Percona and MariaDB. And was happy that my g'old way of sandboxing an instance without installing it still works.

I don't know whether MySQL sandbox is using this approach under the hood, here it goes:

  1. Make sure /etc/mysql/my.cnf is not present or commented out.
  2. Create a ~/.my.cnf with few important lines:
[client]
port        = 3307
host        = 127.0.0.1
socket      = /opt/local/var/mysql/mysql.sock

[mysqld]
gdb # this one is necessary just to sandbox
max_allowed_packet=16M
port=3307
socket=/opt/local/var/mysql/mysql.sock
language=/home/kostja/work/mariadb/5.5/sql/share/english
character-sets-dir=/home/kostja/work/mariadb/5.5/share/charsets
basedir=/home/kostja/work/mariadb/5.5
datadir=/opt/local/var/mysql
server_id=1

These two steps are not strictly necessary, but they allow you to avoid the “mysql will choose the most appropriate cnf file” foo. Of course, you need to make sure that all paths in the configuration file point to correct locations at the source tree, and the data dir exists and is writable.

3. Now we need to populate the data directory. Here's how:

Fire up

shell> mysqld --bootstrap

type

create database mysql

type ctrl-d.

You could do the same in step 4, it's just fun that when nothing else works you can send queries to mysqld using the standard input.

4. Now let's restart mysqld with --skip-grant-tables, create all the necessary system tables and fill them with data:

shell> mysqld --skip-grant-tables

…firing up the mysql command line client:

shell> mysql
use mysql  -- the below scripts don't choose the default database
source /home/kostja/work/mariadb/5.5/scripts/mysql_system_tables.sql
source /home/kostja/work/mariadb/5.5/scripts/mysql_system_tables_data.sql

Once this is all done, we can restart mysqld with no extra switches, issue the necessary grants, and get it going.