MySQL Database migration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.