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