CentOS Linux Change Mysql database directory location specific operations _mysql

Source: Internet
Author: User
Tags centos
Introduction
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 organize the following steps to transfer MySQL from the/var/lib/mysql directory to the/home/mysql_data/mysql directory:

1, first we need to close MySQL, the following command
Service Mysqld Stop
2, then transfer the data, in order to secure the period, we use the Copy 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-a mysql/home/mysql_data/#这样就把数据库复制到/home/mysql_data down there.

Attention: (-A This parameter must be carried, otherwise copy the past permissions on the 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 #为了安全起见, you can drop the original annotation, and then rejoin the line, and change 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 map of/ETC/INIT.D to/ETC/RC.D/INIT.D,
So use the above command, also 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
System operation Dimension Warm reminder: qihang01 original content copyright, reprint please specify the source and the original link

Now that all the changes are complete, let's start MySQL
Service mysqld Start
or reboot Linux
Reboot
If it starts correctly, the modification is successful.

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.