1. Now we create a new directory (if the error does not have which folder is created step-by-step)
[Email protected] mysql]# mkdir/var/lib/data/mysql/
2, MV or CP raw database data Catalog file
First look at the current data file size:
Du-h--max-depth=1 /var
[Email protected] mysql]# cp-a/var/lib/mysql /var/lib/data/mysql/
-A: The effect of this parameter is the same as specifying the "-DPR" parameter;
-D: When a symbolic connection is copied, the destination file or directory is also established as a symbolic connection and points to the original file or directory connected to the source file or directory;
-P: Preserves the properties of the source file or directory;
-R/R: Recursive processing, all files under the specified directory are processed together with subdirectories;
3. Modify the configuration file my.cnf
[[email protected] MySQL] #vim/etc/my.cnf--------------------------------------------------[Client]port=3308Socket= /var/lib/data/mysql/mysql/mysql.sock-----Path to the new storage directory/var/lib/data/mysql/Mysql[mysqld]socket= /var/lib/data/mysql/mysql/mysql.sock-----Path to the new storage directory/var/lib/data/mysql/Mysqldatadir= /var/lib/data/mysql/mysql-----Path to the new storage directory/var/lib/data/mysql/Mysql[mysqld_safe]socket=/var/lib/data/mysql/mysql/mysql.sock-----Path to the new storage directory/var/lib/data/mysql/Mysql[mysql.server]socket=/var/lib/data/mysql/mysql/mysql.sock-----Path to the new storage directory/var/lib/data/mysql/mysql
Generally only change the client and mysqld, the other does not change as if there is nothing.
4. Restart MySQL
[[email protected] MySQL] #service mysqld stop [[email protected] MySQL] #service mysqld start
Here to see a colleague in the process encountered during the start of an infinite wait situation enable SELinux CentOS7 modify MySQL datadir path discovery is selinux caused, here if you encounter this situation can close it.
1, quickly turn off SELinux and use the following command: [[email protected] mysql]#/usr/sbin/setenforce0--close SELINUX immediately [[email protected] mysql]#/usr/sbin/setenforce1--Enable SELINUX now2, permanently close [[email protected] mysql]# vim/etc/selinux/config will selinux=enforcing Change to Selinux=disabled, save after exit # This file controls the state of SELinux on the system.# selinux=Can take one of these three values:# enforcing-SELinux Security Policy isenforced.# Permissive-SELinux Prints warnings instead of enforcing.# disabled-No SELinux Policy isloaded. SELINUX=enforcing# Selinuxtype=Can take one of three values:# targeted-Targeted processes isprotected, # Minimum-Modification of targeted policy. Only selected processes isprotected. # MLS-Multi level Security protection. Selinuxtype=targeted the security policy for obtaining the current SELinux firewall is still enforcing and the configuration file does not take effect. [[Email protected]~]# getenforceenforcing Restart the machine. [[Email protected]~]# Rebootok [[email protected]~]#/usr/sbin/sestatusselinux Status:disabled[[email protected]~]# getenforcedisabled
MySQL library migrated to another partition