Linux Centos Migration MySQL data location
The database is now migrated due to an increase in traffic that causes the disk space on the system disk (20G) to be fully occupied. Mysql
is through yum
the installation.
centos6.5mysql5.1
yum
Installed mysql
Services
View
mysql
The installation path
Execute QuerySQL
'%dir% ';
datadir
is the data path
Transfer operations
New mysql
Data Catalog
mkdir/data/mysqldata
Stop MySQL Service
Service Mysqld Stop
Enter the password and wait for it to stop
/var/lib/mysql
copy the entire directory to/data/mysqlData
/var/lib/mysql /data/mysqldata/
Modify a my.cnf
file
Cp/etc/my. cnf/etc/my. cnf.bakvim/etc/my. cnf
The file contents are as follows, need to be modified datadir
, socket
corresponding directories
[mysqld]default-character-set=utf8#datadir=/var/lib/mysqldatadir=/Data/mysqldata/mysql # # # #socket =/var/lib/mysql/mysql.socksocket=/var/lib/mysql/mysql.sock ####user=mysql# disabling symbolic-links is recommended to Prevent assorted security riskssymbolic-links=0[mysqld_safe]log-error=/ var/log/mysqld.logpid-file=/< Span class= "Hljs-keyword" >var/run/mysqld/mysqld.pid [MySQL] default-character-set=utf8[client] default-character-set=utf8
Modify MySQL startup script/etc/init.d/mysqld
Vim/etc/init.d/mysqld
修改文件中`datadir`路径
"/data/mysqldata/mysql"
Because it is necessary to modify the '/usr/lib64/mysql/mysql_config ' file through the ' Yum ' installation
/usr/lib64/mysql/mysql_config
Modify Content
#ldata ='/var/lib/mysql ' ldata='/data/mysqldata/mysql '#socket ='/var/lib/mysql/mysql.sock ' socket= '/data/mysqldata/mysql/mysql.sock '
Restart MySQL Service
Service mysqld Restart
Execute a querysql
'%dir% ';
datadir
the found path has changed and can run normally sql
, proving that the data can be obtained normally.
Summarize
This operation is on the test server operation, the mood is still very tense, if need to operate the database on the line, must be cautious, must be cautious, must be cautious. Be sure to pay attention to backups. This migration is guaranteed to be completed in 20 minutes, thus reducing the loss.
Note: Warning:
: Warning: yum
Modify/usr/lib64/mysql/mysql_config file as required by installation
Linux Centos Migration MySQL data location