centos7 mysql5.7主从数据迁移

主从为rpm包安装方式,版本为mysql - 5.7.18 - 1. - el7.x86_64.rpm包。tar

主从配置文件如下所示:

主服务器:

# egrep -v "^$|^#"/etc/my.cnf

[mysqld]

socket=/var/lib/mysql/mysql.sock

datadir=/data/mysql_data

character_set_server=utf8

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

symbolic-links=0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

server-id=1

log-bin=mysql-bin

binlog_format=mixed

innodb_flush_log_at_trx_commit=1

sync_binlog=1

expire_logs_days=15

relay_log=mysql-realy-bin

从服务器:

# egrep -v "^$|^#"/etc/my.cnf

[mysqld]

socket=/var/lib/mysql/mysql.sock

datadir=/data/mysql_data

character_set_server=utf8

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

symbolic-links=0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

server-id=2

log_bin=mysql-bin

relay_log=mysql-relay-bin

log-slave-updates=on

expire_logs_days=15

replicate-ignore-db=sys

replicate-ignore-db=mysql

replicate-ignore-db=information_schema

replicate-ignore-db=performance_schema

2、变更步骤

首先关闭主从数据库服务

修改配置文件/etc/my.cnf ,我这里只修改下面一行

然后把数据库数据目录拷贝到目标目录下,这里迁移到/opt/tmp 目录下

# cp -a/data/mysql_data/opt/tmp/

最后启动主从mysql服务,并进行验证


centos7 mysql5.7主从数据迁移