Friday, July 11, 2008

changing the directory in which mysql databases are stored

By default all databases are saved in /var/lib/mysql
Because this is in the root partition you might quickly use up root
partition if you create large databases. If you want to change this
directory to, for example, /home/mysql do the following.

creating the new datadir
sudo mkdir /home/mysql

stop mysql.
sudo /etc/init.d/mysql stop

edit my.cnf (mysql config file)
sudo emacs -nw /etc/mysql/my.cnf

change datadir under [mysqld] from /var/lib/mysql to /home/mysql

edit apparmour (Ubuntu speciality)
sudo emacs -nw /etc/apparmour.d/usr.sbin.mysqld
change lines that contain /var/lib/mysql/ to /home/mysql/

copy the databases to new directory.
sudo mv /var/lib/mysql/* /home/mysql/.

change file ownership (should be owned by user mysql and group mysql)
sudo chown -R /home/mysql

restart apparmour
sudo /etc/init.d/apparmour restart

start mysql
sudo /etc/init.d/mysql start

No comments:

Post a Comment

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1