Liunx Database Change Directory

Source: Internet
Author: User

A few days ago found because MySQL database is too large, the default installed / var disk can no longer accommodate the newly added data, only to find ways to transfer the data directory. There are a lot of related articles on the Internet to transfer the database directory of the article, but the process of the reprint will have some errors, because most people have not tested, this article is tested in Linux to share the good after sharing to everyone.

This article is a simple collation of these days to MySQL moves from below the/var/lib/mysql directory to /home/data/mysql below.

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

#systemctl Stop Mariadb.service

then the transfer data, for security period, we use the Copy command CP, first find The original MySQL directory

#cd/var/lib

and then execute CP Command

#cp-A mysql/home/data/

In this way, the database is copied to the/home/data under, note - A This parameter must carry, or copy the past permission is not right. If the database is larger, the time will be longer and may be timed out.

Then we modify the configuration file, a total of three, below I one by one description:

#vi/etc/my.cnf

after opening , modify the DataDir directory to /home/data/mysql, and Change the socket to /home/ Data/mysql/mysql.sock, for security reasons, you can put the original comment off, and then re-add a line, changed to the current directory.

#vi/usr/bin/mysqld_safe

This is also the directory to modify DataDir

Here's a link to create a mysql.sock : #优化

#ln-S/home/data/mysql/mysql.sock/var/lib/mysql/mysql.sock

Now that all the changes are complete, start MySQL below

#systemctl Start Mariadb.service

or Restart Linux

#reboot

After rebooting or logging in to the database

Mysql-s/home/data/mysql/mysql.sock-u root-p123456 # capital S

Liunx Database Change Directory

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.