Skip to content

Instantly share code, notes, and snippets.

@werkshy
Created March 29, 2013 14:37
Show Gist options
  • Save werkshy/5271232 to your computer and use it in GitHub Desktop.
Save werkshy/5271232 to your computer and use it in GitHub Desktop.
Script to start a second mysql server using ramdisk/tmpfs for unit tests.
#!/bin/bash
DATADIR=/dev/shm/mysql
TMPDIR=/dev/shm/mysql_tmp
MYSQL_SOCKET=/dev/shm/mysql.sock
pkill -9 -f mysql.*datadir.*$DATADIR
mkdir -p $DATADIR
mkdir -p $TMPDIR
chown -R mysql.mysql $DATADIR
chown -R mysql.mysql $TMPDIR
rm -f $DATADIR/ib*
echo "=== Installing MySQL DB ==="
mysql_install_db --user=mysql --datadir=$DATADIR
# Note: this only overrides stuff in /etc/my.cnf. Other settings are taken from
# there and are quite important!
echo "=== Starting IN-MEMORY MYSQL SERVER ==="
/usr/sbin/mysqld --port=3307 \
--datadir=$DATADIR \
--innodb_data_home_dir=$DATADIR \
--innodb_log_group_home_dir=$DATADIR \
--tmpdir=$TMPDIR \
--socket=$MYSQL_SOCKET \
--log-error=/dev/shm/mysql.err &
echo "=== Waiting ==="
sleep 10
echo "=== Setting root password ==="
export MYSQL_SOCKET
export MYSQL_PASSWORD=bunnies
mysql --socket=$MYSQL_SOCKET -u root -e "SET PASSWORD = PASSWORD('bunnies')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment