Mysql Database Migrate Data folder location detailed steps _mysql

Source: Internet
Author: User

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

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.