CentOS change MySQL storage directory location Instance tutorial

Source: Internet
Author: User
Tags chmod socket

MySQL default data file storage directory for/var/lib/mysql

The following steps are required if you want to move the directory to/home/mysqldata:

1, the home directory to establish Mysqldata directory

The code is as follows Copy Code

Cd/home
mkdir Mysqldata

2, stop the MySQL process

The code is as follows Copy Code

Mysql-u root-p shutdown

3. Move/var/lib/mysql Entire directory to/home/mysqldata

The code is as follows Copy Code

mv/var/lib/mysql/home/mysqldata/

So the MySQL data file is moved to the/home/mysqldata/mysql.

4, find my.cnf configuration file
If there is no MY.CNF configuration file in the/etc/directory, please go to/usr/share/mysql/to find my-medium*.cnf file, copy to/etc/and rename My.cnf
The order is as follows:

The code is as follows Copy Code

[Root@lxy mysql]# cp/usr/share/mysql/my-medium.cnf/etc/my.cnf

5. Edit/ETC/MY.CNF
To ensure that MySQL works properly, you need to indicate where the Mysql.sock file will be generated. Modify Socket=/var/lib/mysql/mysql.sock

The code is as follows Copy Code

Socket=/home/mysqldata/mysql/mysql.sock

The operation is as follows:

The code is as follows Copy Code

VI my.cnf (with VI tool to edit MY.CNF file, find the following data modification)

# the MySQL Server[mysqld]
Port = 3306
#socket =/var/lib/mysql/mysql.sock (original content, in order to be more secure with "#" comment on this row)
Socket =/home/mysqldata/mysql/mysql.sock (plus this row)

6, modify the MySQL startup script/etc/init.d/mysql

Change the Datadir=/var/lib/mysql line to the actual storage path: Home/mysqldata/mysql

The code is as follows Copy Code

[Root@lxy etc]# Vi/etc/init.d/mysql
#datadir =/var/lib/mysql (note this row)
Datadir=/home/mysqldata/mysql (plus this row)

Finally make a mysql.sock link:

The code is as follows Copy Code

Ln-s/home/mysqldata/mysql/mysql.sock/var/lib/mysql/mysql.sock (you need to copy it from/home/mysqldata/mysql.)

7, restart the MySQL service

The code is as follows Copy Code
/etc/init.d/mysqld start

or restart Linux with the reboot command
If the work is moving normally, it will be successful, otherwise check the previous 7 steps.

8, the last change the permissions of the database

The code is as follows Copy Code

[Root@localhost ~]# chown-r mysql:mysql/home/mysqldata/mysql/← Change the ownership of the database for MySQL
[Root@localhost ~]# chmod 700/home/mysqldata/mysql/test/← Change Database directory property to 700
[Root@localhost ~]# chmod 660/home/mysqldata/mysql/test/*← Change the properties of the data in the database to 660

9, all done!

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.