Since Yum installs MySQL, the database's data directory defaults to/var/lib, and it needs to be moved to the/data partition for data security reasons. The steps are as follows:
First, turn off Apache and MySQL.
Copy 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 MV command instead of CP command? should be specific to the Linux file system, MV command can retain all the attributes and permissions of the file, especially the SELinux attribute. If the CP command, you need to go back to set the MySQL folder SELinux properties, I have a headache selinux so can avoid.
Copy Code code as follows:
Mv-r/var/lib/mysql/data/mysql
third, modify the MySQL configuration file/etc/my.cnf. Change the datadir and socket paths to the/data directory.
Copy Code code as follows:
[Mysqld]
#datadir =/var/lib/mysql------The default path of the original system
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, otherwise the PHP site will not be able to connect to the database. PHP.ini The default socket path is empty, and the default is to point to/var/lib/mysql, so you also change to/data/mysql.
Copy Code code as follows:
[MySQL]
Mysql.default_socket =/home/mysql/mysql.sock
[Mysqli]
Mysql.default_socket =/home/mysql/mysql.sock
Five, start Apache.mysql.
Copy Code code as follows:
Service httpd Start
Service mysqld Start