成都网站建设设计

将想法与焦点和您一起共享

mysql本地数据目录迁移

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

伊金霍洛ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

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 释放空间即可,删除别的文件也行,只要能释放些空间即可。

完成


文章标题:mysql本地数据目录迁移
文章网址:http://chengdu.cdxwcx.cn/article/pgidps.html