How to move MySQL data directory in Ubuntu Server
By Mikael Ståldal
By default, the MySQL data is placed in /var/lib/mysql
, which is a reasonable default. However, sometimes you want to place it somewhere else, such as on an other file system. Using a symlink doesn’t seem to work, so you have follow this procedure.
To move the MySQL data directory from /var/lib
to /mnt/mydata
, run these commands as root:
apt-get install mysql-server
service mysql stop
mv /var/lib/mysql /mnt/mydata/
- replace
/var/lib/mysql
with/mnt/mydata/mysql
in/etc/passwd
– mysql/etc/mysql/my.cnf
– [mysqld] datadir/etc/apparmor.d/usr.sbin.mysqld
(twice)
service mysql start