Skip to content

Instantly share code, notes, and snippets.

@schmurfy
Created March 12, 2012 22:35
Show Gist options
  • Select an option

  • Save schmurfy/2025123 to your computer and use it in GitHub Desktop.

Select an option

Save schmurfy/2025123 to your computer and use it in GitHub Desktop.
#!/bin/sh
# 100Mo
SIZE=$((100 * 1048576 / 512))
BASEDIR="/usr/local/Cellar/mysql/5.5.15"
BIND_ARGS="--socket=/tmp/mysql_ram.sock"
# create ramdisk
echo "Creating RAMDISK..."
RD_PATH=`hdiutil attach -nomount ram://$SIZE`
# format new volume
echo "Formatting RAMDISK ($RD_PATH)..."
diskutil erasevolume HFS+ "ramdisk" $RD_PATH > /dev/null
cleanup(){
echo "Destroying RAMDISK ($RD_PATH)..."
hdiutil detach $RD_PATH > /dev/null
}
trap cleanup INT TERM EXIT
# create the database
echo "Creating database..."
/usr/local/bin/mysql_install_db \
--basedir=$BASEDIR \
--datadir=/Volumes/ramdisk > /dev/null
trap 'mysqladmin --user=root $BIND_ARGS refresh & wait' 1 # HUP
trap 'mysqladmin --user=root $BIND_ARGS shutdown & wait' 2 3 15 # INT QUIT and TERM
# start the server
echo "Starting server..."
/usr/local/bin/mysqld \
--no-defaults \
--basedir=$BASEDIR \
--datadir=/Volumes/ramdisk \
--log-error=/Volumes/ramdisk/mysql.ramdisk.err \
--pid-file=/Volumes/ramdisk/mysql.ramdisk.pid \
--port=3308 \
--console \
$BIND_ARGS &
wait
# Call cleanup manually
trap - INT TERM EXIT
cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment