Linux mysql change mysql data file directory location

Source: Internet
Author: User

Linux mysql change mysql data file directory location



Background: A recent company server alarm, disk space alarm super threshold. Originally MySQL database Data directory is particularly large, and now I want to change the directory of data files. The default directory is the original.


The default data file storage directory for MySQL is/var/lib/mysql. The following steps are required if you want to move the directory to/home/data:
1. Set up the data directory in the home directory
Cd/home
mkdir data


2. Stop the MySQL service process:
Mysqladmin-u root-p shutdown


3. Move/var/lib/mysql Entire directory to/home/data
mv/var/lib/mysql/home/data/
This will move the MySQL data file to/home/data/mysql.


4. Locate the MY.CNF configuration file
If there is no MY.CNF configuration file under the/etc/directory, locate the *.cnf file under/usr/share/mysql/, and copy one of them to/etc/and rename it to MY.CNF). The command is as follows:
[Email protected] mysql]# CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF


5. Edit the MySQL configuration file/etc/my.cnf
To ensure that MySQL works correctly, you need to indicate where the Mysql.sock file is generated. Modify the value in the Socket=/var/lib/mysql/mysql.sock line to the right of the equals sign:/home/mysql/mysql.sock. The operation is as follows:
VI my.cnf (Edit the My.cnf file with VI tool, find the following data to modify)
# The MySQL server
[Mysqld]
Port = 3306
#socket =/var/lib/mysql/mysql.sock ("#" Comment this line, fallback convenience. )
Socket =/home/data/mysql/mysql.sock (plus this line)



6. Modify MySQL startup script/etc/init.d/mysql


Finally, the MySQL startup script needs to be modified/etc/init.d/mysql, the path to the right of the equal sign in the Datadir=/var/lib/mysql line is changed to your current actual storage path: Home/data/mysql.
[Email protected] mysql]# Vi/etc/init.d/mysql
#datadir =/var/lib/mysql (Note this line)
Datadir=/home/data/mysql (plus this line)
7. Restart MySQL Service
/etc/init.d/mysql start
or restart Linux with the reboot command
If the work is moving properly, otherwise check the previous 7 steps.

Also pay attention to the owner and permission of the directory.


This article is from the "Technical Achievement Dream" blog, please be sure to keep this source http://pizibaidu.blog.51cto.com/1361909/1696677

Linux mysql change mysql data file directory location

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.