Centos7 下关于MySQL5.7.22的主从部署
su root
1.分别停止MySQL服务
/etc/init.d/mysql stop
2.修改master的my.cnf文件
3.启动master服务
/etc/init.d/mysql start
4.登录MySQL
mysql -h localhost -u root -p
5.创建用户用于从库同步数据
mysql> GRANT REPLICATION SLAVE ON *.* TO 'backup'@'172.16.2.77' IDENTIFIED BY '123456';
6.创建需要同步的数据库
create database energy_system default character set utf8 collate utf8_general_ci;
create database energy_battery_supplier default character set utf8 collate utf8_general_ci;
create database energy_vehicle_produce default character set utf8 collate utf8_general_ci;
create database energy_vehicle_sale default character set utf8 collate utf8_general_ci;
create database energy_support default character set utf8 collate utf8_general_ci;
create database energy_battery_repair default character set utf8 collate utf8_general_ci;
create database energy_battery_replace default character set utf8 collate utf8_general_ci;
7.获取二进制日志信息
mysql > SHOW MASTER STATUS;
8.修改slave的my.cnf文件
9.启动slave服务
/etc/init.d/mysql start
10.给从库设置主库
mysql -h localhost -u root -p
mysql> CHANGE MASTER TO
-> MASTER_HOST='172.16.2.78',
-> MASTER_USER='backup',
-> MASTER_PASSWORD='123456',
-> MASTER_LOG_FILE='mysql-bin.000003',
-> MASTER_LOG_POS=449275;
10.启动同步进程
start slave;
11.查看同步状态
参考资料:
https://dev.mysql.com/doc/refman/5.7/en/replication-howto-masterbaseconfig.html