How to change the location of the MySQL database directory in CentOS

Source: Internet
Author: User
Keywords Mysql centos
Tags added aliyun centos change close copy data default

Because the MySQL database is too large, the default installed var disk can no longer accommodate the newly added data, there is no way, can only find ways to transfer the data directory.

Let me simply tidy up the next few days to the MySQL from the/var/lib/mysql directory under the transfer to/home/mysql_data/mysql under the specific operation

1, first we need to close MySQL, the command is as follows:

&http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP; Service Mysqld Stop

2, then the transfer of data, in order to secure the period, we use the copy of the command CP, first find the original MySQL directory

Cd/var/lib
ls

After running this command, you will see the MySQL directory, and then execute the CP command

CP mysql/home/mysql_data/

So we can copy the database down to/home/mysql_data.

Note: (-A This parameter must be carried, otherwise the right to copy the past is wrong.) )
If the database is relatively large, time will be longer, may be timed out, how to set up SSH does not time out the way, please find relevant information themselves.

3, then we modify the configuration file, a total of three, the following I one by one description:

Modify first file: Back up Cp/etc/my.cnf/etc/my.cnfbak before modifying

Vi/etc/my.cnf

The directory to modify DataDir after opening is/home/mysql_data/mysql,

Change the socket to/home/mysql_data/mysql/mysql.sock, and for security reasons, you can drop the original annotation and rejoin the line to the current directory.

Modify the second file: Back up Cp/etc/init.d/mysqld/etc/init.d/mysqldbak before modifying

Vi/etc/init.d/mysqld

Note: The exact position is/etc/rc.d/init.d/mysqld, because here is a/etc/init.d to/ETC/RC.D/INIT.D mapping, so use the above command can also be simple.

In the Datadir/var/lib/mysql line, change the path to the right of the equals sign to your current path:/home/mysql_data/mysql

Modify third file: Back up Cp/usr/bin/mysqld_safe/usr/bin/mysqld_safebak before modifying

Vi/usr/bin/mysqld_safe

This is also the directory that modifies datadir for/home/mysql_data/mysql

4, the following need to establish a mysql.sock link:

Ln-s/home/mysql_data/mysql/mysql.sock/var/lib/mysql/mysql.sock

Now that all the changes are complete, let's start MySQL

Service mysqld Start

or reboot Linux

Reboot

If it starts properly, it's basically fine.

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.