MySQL database migration data folder location detailed step _ MySQL

Source: Internet
Author: User
Tags php website
MySQL database migration data folder location detailed steps bitsCN.com

Because the data directory of the database is under/var/lib by default when mysql is installed in yum, it needs to be moved to the/data partition for data security considerations. The procedure is as follows:
1. disable apache and mysql.

Service httpd stop
Service mysqld stop
2. move the mysql directory mv under/var/lib to the data directory.
Why the mv command instead of the cp command? For linux file systems, mv commands can retain all attributes and permissions of files, especially selinux attributes. If you use the cp command, you need to go back and set the selinux attribute of the mysql folder. because of the headache, selinux can be avoided.

Mv-R/var/lib/mysql/data/mysql
3. modify the mysql configuration file/etc/my. cnf. Change the datadir and socket paths to the/data Directory.

[Mysqld]
# Datadir =/var/lib/mysql ------ default path of the original system
Datadir =/home/mysql ------ existing path
# Socket =/var/lib/mysql. sock ------ the original socket path is now
Socket =/home/mysql. sock ------ Current path

[Mysqld_safe]
Socket =/home/mysql. sock ----- current path
[Client]
Socket =/home/mysql. sock ----- current path
[Mysql. server]
Socket =/home/mysql. sock ----- current path
4. modify the socket path in the php configuration file (/etc/php. ini.
Sure, do not forget to specify the socket path in php. ini. Otherwise, the php website will not be able to connect to the database. In php. ini, the default socket path is null. the default path is/var/lib/mysql. Therefore, you must change it to/data/mysql.

[Mysql]
Mysql. default_socket =/home/mysql. sock
[Mysqli]
Mysql. default_socket =/home/mysql. sock
5. start apache. mysql.

Service httpd start
Service mysqld start

BitsCN.com

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.