In some cases, it may be necessary to move the mysql database from the default directory (/ var / lib / mysql) to another directory or even to a separate partition. For example, to protect databases from damage, in case the file system on the primary partition is damaged.
The topic of creating new sections in this note will not be touched. I will describe only what needs to be done when the section for new database hosting is ready.
First you need to stop the mysql server.
# service mysql stop
Then copy the contents of / var / lib / mysql to the new destination. For example, this will be the / databases section.
# cp -pR / var / lib / mysql / databases
The -p switch saves the original file settings: owner, group, permissions, etc.
The -R switch is responsible for recursively copying directories.
The final step will be editing the mysql configuration file. Open the file /etc/my.cnf and find the variable datadir . Its default value is:
datadir = / var / lib / mysql
Specify the new location of the database:
datadir = / databases / mysql
We start mysql with the service mysql start command. Old directory can be deleted. Any errors can be found in the /var/log/daemon.log log file, or in the / var / log / syslog file.
There were problems with the transfer. The description from http://blog.bethrezen.ru/2009/12/perenos-mysql-v-druguyu-papku-razdel-na-debian-ubuntu.html helped