Ubuntu :: Move datadir directory in MySQL
:: What’s MySQL
MySQL is open-source relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases.
:: How to move datadir MySQL directory in Linux Ubuntu
+ Stop mysqld
/etc/init.d/mysql stop
+ Move or copy mysql data to new location (/home)
mv /var/lib/mysql /home
or
rsync -aAXv /var/lib/mysql /home
+ Change permission in new location
chown -R mysql.mysql /home/mysql
+ Setting my.cnf
vi /etc/mysql/my.cnf
commented or change in this:
# datadir = /var/lib/mysql
add or change to this line:
datadir = /home/mysql
+ Add new location path in apparmor.d
vi /etc/apparmor.d/usr.sbin.mysqld
commented or change in these line:
#/var/lib/mysql/ r, #/var/lib/mysql/** rwk,
add or changed with these:
/home/mysql/ r, /home/mysql/** rwk,
+ Reload apparmord
/etc/init.d/apparmor reload
+ Starting mysqld using new location datadir
/etc/init.d/mysql start