为了给个vmware装模板,搞了两个磁盘,没想到挖坑给自己了,要装mysql数据库,同事手快,一下就装完了,系统盘就100G,数据盘几百G……
网上好多版本mysql的迁移,居然没有一个合用
最接近的是
https://www.cnblogs.com/Lans-word/p/12080177.html
完全按照例子做,没有问题。
稍微修改下目录就从/var/log/mysqld.log爆出各种奇怪的问题,数据也启动不起来,最终只有设置成777权限才可以用,显然在生产环境是不可以的。
没有功夫研究权限的问题了
上思路,建立/data目录,做个软连接
ln -s /data /home/mysql_data/mysql
接着可以参照例子做,当然这里还是多了一层目录
步骤:
1、创建目标路径mkdir -p /data
2、关闭MySQLsystemctl stop mysqld
3、复制数据文件cp -arp /var/lib/mysql /data
4、修改配置文件/etc/my.cnf
将datadir和socket中的原路径修改为目标路径datadir=/home/mysql_data/mysql/mysql
socket=/home/mysql_data/mysql/mysql/mysql.sock
5、启动MySQL服务systemctl start mysqld
和例子中的selinux完全无关
我的环境Centos7.3
数据mysql5.7
上成品,这是/etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
datadir=/home/mysql_data/mysql/mysql
socket=/home/mysql_data/mysql/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
~
总结,一定是权限的问题。/home下的权限和其他目录的难道有不一样?