Requirements: MySQL's original directory is out of space, need to migrate MySQL directory in this machine
Mkdir-p/home/mysql3306/data
Mkdir-p/home/mysql3306/log
Mkdir-p/home/mysql3306/run/mysqld
Original directory:/var/lib/mysql
Migration Destination Directory:/home/mysql3306/data
Cp-r/var/lib/mysql/*/home/mysql3306/data/
Chown-r mysql.mysql/home/mysql3306
————————————————————————————
Vim/etc/my.cnf
#join_buffer_size = 128M
#sort_buffer_size = 2M
#read_rnd_buffer_size = 2M
#datadir =/var/lib/mysql
Datadir=/home/mysql3306/data
#socket =/var/lib/mysql/mysql.sock
Socket=/home/mysql3306/data/mysql.sock
Lower_case_table_names=1
#Disabling Symbolic-links is recommended to prevent assorted security risks
Symbolic-links=0
max_connections=1000
max_connect_errors=300
#Recommended in standard MySQL setup
Sql_mode=no_engine_substitution,strict_trans_tables
[Mysqld_safe]
#log-error=/var/log/mysqld.log
Log-error=/home/mysql3306/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
Pid-file=/home/mysql3306/run/mysqld/mysqld.pid
[MySQL] # # Here Add 2 lines, avoid mysql-uroot-p when the report can not find sock file
Socket=/home/mysql3306/data/mysql.sock
WQ: Save here
————————————————————————————————
VIM/ETC/INIT.D/MYSQLD # # Modify the following variables
Get_mysql_option mysqld datadir "/home/mysql3306/data"
#get_mysql_option mysqld datadir "/var/lib/mysql"
Datadir= "$result"
Get_mysql_option mysqld Socket "$datadir/mysql.sock"
Socketfile= "$result"
Get_mysql_option mysqld_safe log-error "/home/mysql3306/log/mysqld.log"
#get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
Errlogfile= "$result"
Get_mysql_option mysqld_safe pid-file "/home/mysql3306/run/mysqld/mysqld.pid"
#get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
——————————————————————————————————
/etc/init.d/mysqld stop
/etc/init.d/mysqld start
Mysql-uroot-p Verify that the data is
DESC table name;
Error sqlstate[hy000]: General error:1030 Got error * from storage engine
This is because the/tmp directory has no space, rm-rf/var/lib/mysql free space, delete other files are also OK, as long as you can free up some space.
Complete
MySQL Local Data Directory Migration