In CentOS7, the MySQL database file is placed by default in/var/lib, and sometimes the partition is smaller, it needs to be migrated to the larger partition, by the following method
1. Stop the MySQL service and copy the/var/lib/mysql directory to a new directory, such as/home/mysql
Cp-r/var/lib/mysql/home/
2, modify the/etc/my.conf, find the following two lines:
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Change into
Datadir=/home/mysql
Socket=/home/mysql/mysql.sock
3. This time if restarting the MySQL service will error:
Job for Mysqld.service failed because the control process exited with error code. See "Systemctl Status Mysqld.service" and "Journalctl-xe" for details.
when installing MySQL, a MySQL user and a MySQL user group were created, and the directory where the files were stored/var/lib/mysql the MySQL user, and after the migration,/home/mysql belonged to the root user and the ROot user group. (This depends on what account you use to log in to CentOS.) In this case, it is only possible to belong to the root user, because the general user does not have permission to write in home/home, MySQL must not have permission to operate the file belonging to the root, so the error.
Modify the/home/mysql directory and the properties of all the files below to make them belong to the MySQL user
Chown-r Mysql:mysql \home\mysql
4, after completing the above steps still cannot start the MySQL service, because of the selinux limit, turn it off, modify the/etc/selinux/config file:
Selinux=disabled
Finally restart the MySQL service
MySQL Modify database file storage location