mysql 本地数据目录迁移

  • by

需求:mysql的原目录没空间了,需要在本机中迁移mysql目录

mkdir -p /home/mysql3306/data
mkdir -p /home/mysql3306/log
mkdir -p /home/mysql3306/run/mysqld

原目录:/var/lib/mysql
迁移目标目录:/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] ## 这里加2行,避免mysql -uroot -p的时候报找不到sock文件
socket=/home/mysql3306/data/mysql.sock
wq: 这里保存
———————————————————————————————— 
vim /etc/init.d/mysqld ## 修改下面的变量
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 验证下是否数据都在
desc 表名; 
保错 SQLSTATE[HY000]: General error: 1030 Got error 28 from storage engine
这是因为/tmp 目录没空间了,rm -rf /var/lib/mysql 释放空间即可,删除别的文件也行,只要能释放些空间即可。

完成

发表评论

电子邮件地址不会被公开。 必填项已用*标注

20 + 7 =