Change Centos under MySQL source data storage directory (datadir)

MySQL after installation, a source default data stored in / var / lib / mysql / directory, under normal circumstances, the directory in the root directory, since Linux systems where the default root mount limited disk capacity, with production continue to produce data, the directory will become increasingly large, if disk space is insufficient, Mysql will be reported Got error 28 from storage engine error, so it is best to make changes to MySQL data directory. See MySQL source data storage path command is
show variables like 'datadir';
results are shown:
   
Stop MySQL server command: service mysql stop.
Create a new data directory / home / datadir, command: mkdir / home / datadir
copy the previous data files to the new data directory, the command is: cp -rf / var / lib / mysql / home / datadir
change the configuration file the my.cnf, command:
Vim /etc/my.cnf
parameter datadir modify
datadir = / home / datadir / mysql
parameter our sock (there are two, respectively in the client and mysqld) are modified to socket = / home / datadir after /mysql/mysql.sock modified as shown below:
then,: wq save and exit.

Modify the MySQL startup script command:
vim /etc/init.d/mysql.
# datadir = / var / lib / mysql ( comment this line)
  DATADIR = / Home / DATADIR / MySQL (add this line), as shown:

Then: wq to save and exit
command to solve the problem directory permissions:
chown -R MySQL: MySQL / Home / datadir / MySQL
if the firewall is not closed then turn off the firewall: 0 setenforce
Service Start MySQL, start MySQL again using the
show variables like 'datadir'; command View datadir, as follows:

Guess you like

Origin www.cnblogs.com/ExMan/p/11271850.html