Skip to content

Instantly share code, notes, and snippets.

@simodima
Last active October 10, 2015 01:07
Show Gist options
  • Save simodima/3607686 to your computer and use it in GitHub Desktop.
Save simodima/3607686 to your computer and use it in GitHub Desktop.
Ramdisk
#Stop mysql service
service mysql stop
# Crate your ramdisk partition
mkdir /mnt/myramdisk
mount -t tmpfs -o size=150M tmpfs /mnt/myramdisk
# Set the correct permissions
chown mysql /mnt/myramdisk
chgrp mysql /mnt/myramdisk
chmod 775 /mnt/myramdisk
# Create this file "/etc/mysql/conf.d/override.cnf"
# with -->
[mysqld]
datadir = /mnt/myramdisk/databases/
# Modify AppArmor config for mysql service
vim /etc/apparmor.d/usr.sbin.mysqld
#add these lines
/mnt/myramdisk/ r,
/mnt/myramdisk/** rwk,
# One "RAMabase" for file :-)
touch /var/lib/mysql/databases/mysql
touch /var/lib/mysql/databases/phpmyadmin
#Restart the services
/etc/init.d/apparmor restart
service mysql start
#-------------SCRIPT-AT-STARTUP-----------------#
#!/bin/bash
[ "$#" -eq 1 ] || die "1 argument required, $# provided"
if [ "$1" == "ram" ]; then
FILES=/var/lib/mysql/databases/*
RAMDISK="/mnt/myramdisk"
if [ ! -e "$RAMDISK/databases" ]; then
mkdir /mnt/myramdisk/databases
fi
for f in $FILES
do
echo "Processing $f file..."
if [ ! -e "$RAMDISK/databases/$(basename $f)" ]; then
mkdir "$RAMDISK/databases/$(basename $f)"
fi
if [ ! -e "/var/lib/mysql/$(basename $f)" ]; then
echo "ERROR $f file ✗"
else
cp -R "/var/lib/mysql/$(basename $f)" "/mnt/myramdisk/databases/"
fi
done
chown -R mysql:mysql /mnt/myramdisk/
echo "
[mysqld]
datadir = $RAMDISK/databases/
" > /etc/mysql/conf.d/override.cnf
else
echo "" > /etc/mysql/conf.d/override.cnf
fi
service mysql stop
service mysql start
#------------------------------------------------#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment