MySQL Database Data Directory Migration under CentOS

Source: Internet
Author: User

The company's new online information site, independent host, Raid5,lamp architecture. As the information network is oriented to small industries, the initial estimate of a two-year visit volume of pressure, therefore, when the server system is set up, it is simply a separate data area as a database and website program of the zone, other according to Linux default partition. Apache,mysql,php are installed using Yum (also tried to install independently, but in real-world use, found not as easy as Yum, of course, if it is a large-scale application site, it is not easy to estimate Yum)

Since Yum installs MySQL, the database data directory defaults to/var/lib, which is moved to the/data partition for data security reasons. The steps are as follows:

1. Close Apache and MySQL.

service httpd stopservice mysqld stop




2, 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.


mv  /var/lib/mysql /data/mysql

3. Modify the MySQL configuration file/etc/my.cnf. Change the path of the datadir and socket to the/data directory.



[Mysqld]#datadir =/var/lib/mysql------The original system default pathdatadir=/Data/mysql------an existing path#socket =/var/lib/mysql/mysql.sock------The original socket path is nowsocket=/Data/mysql/mysql.sock------existing path [Mysqld_safe]socket=/Data/mysql/mysql.sock-----existing path [client]socket=/< Span class= "Hljs-class" >data/mysql/mysql.sock                   -----existing path [Mysql.server]socket=/data/mysql/mysql.sock                   -----existing path     

4. 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.

[mysql]mysql.default_socket = /data/mysql/mysql.sock[mysqli]mysql.default_socket = /data/mysql/mysql.sock

5, restart the apache.mysql.

Done!!!

MySQL Database Data Directory Migration under CentOS

Related Article

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.