Since Yum installs MySQL, the database's data directory is under/var/lib by default and needs to be moved to the/data partition for data security reasons. The steps are as follows:
One, close Apache and MySQL.
Copy the code code as follows:
Service httpd Stop
Service Mysqld Stop
Second, the/var/lib under the MySQL directory MV (MOBILE) to the data directory.
Why use the MV command instead of the CP command? For Linux file system specificity, the MV command preserves all attributes and permissions of the file, especially the SELinux attribute. If the CP command, you need to go back to set the MySQL folder's SELinux properties, I am very headache selinux so can avoid.
Copy the code code as follows:
Mv-r/var/lib/mysql/data/mysql
Third, modify the MySQL configuration file/etc/my.cnf. Change the path of the datadir and socket to the/data directory.
Copy the code code as follows:
[Mysqld]
#datadir =/var/lib/mysql------The original system default path
Datadir=/home/mysql------Existing Path
#socket =/var/lib/mysql/mysql.sock------The original socket path is now
Socket=/home/mysql/mysql.sock------Existing Path
[Mysqld_safe]
Socket=/home/mysql/mysql.sock-----Existing Path
[Client]
Socket=/home/mysql/mysql.sock-----Existing Path
[Mysql.server]
Socket=/home/mysql/mysql.sock-----Existing Path
Iv. Modify the socket path in the PHP configuration file (/etc/php.ini).
Yes, do not forget the php.ini also to indicate the path of the socket, or PHP Web site will not be able to connect to the database. PHP.ini The default socket path is empty, the default is to point to/var/lib/mysql, so you should also change to/data/mysql.
Copy the code code as follows:
[MySQL]
Mysql.default_socket =/home/mysql/mysql.sock
[Mysqli]
Mysql.default_socket =/home/mysql/mysql.sock
Five, start the apache.mysql.
Copy the code code as follows:
Service httpd Start
Service mysqld Start
MySQL Database migration