Mysql-MHA高可用实验测试-主从复制搭建
Mysql-MHA高可用实验测试-主从复制搭建Mysql-MHA高可用实验测试-主从复制搭建环境信息:1.安装mysql这里就不再介绍mysql的安装2.配置mysql主从a)配置my.cnfmaster上操作:?1rootmaster mysql# vi /etc/my.cnf添加如下:?123456789server_id =1 log-bin=mysql-bin binlog_format=mixed slave1上操作 rootslave1 # vi /etc/my.cnf添加如下:?1234567server_id =2 log-bin=mysql-bin binlog_format=mixed relay_log_purge=0slave2上操作乐淘棋牌http:/www.letaoqpyx.com添加如下:?123456789101112131415rootslave2 # vi /etc/my.cnf server_id =3 log-bin=mysql-bin relay_log=mysql-relay-bin max_relay_log_size=2G log_slave_updates=1 read_only=1 relay_log_purge=0注意:以上配置完之后要重启数据库b)搭建master上操作:?12345678910111213141516171819202122232425262728293031mysql> grant replication slave on *.* to mysql'192.168.180.%' identified by 'mysql' mysql> flush privileges; mysql> stop slave; #设置复制权限账号 mysql> grant all privileges on *.* to 'mha''192.168.180.%' identified by 'mysql' mysql> reset master; mysql> show master statusG; * 1. row * File: mysql-bin.000001 Position: 154 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec) ERROR: No query specifiedslave1 上操作:?123456789101112131415mysql> grant replication slave on *.* to mysql'192.168.180.%' identified by 'mysql' mysql> grant all privileges on *.* to 'mha''192.168.180.%' identified by 'mysql' mysql> flush privileges; mysql> reset master; mysql> stop slave; mysql> change master to master_host='192.168.180.56',master_port=3306,master_user='mysql',master_password='mysql' mysql> start slave; mysql> show slave statusG;slave2上操作:?12345678910111213mysql> reset master; mysql> stop slave; mysql> grant all privileges on *.* to 'mha''192.168.180.%' identified by 'mysql' mysql> flush privileges; mysql> change master to master_host='192.168.180.56',master_port=3306,master_user='mysql',master_password='mysql' mysql> start slave; mysql> show slave statusG;3.测试:在master上创建一个test数据库,在test里创建一个test的表master上操作移动电玩城http:/www.44226.net?1234567891011121314151617181920212223242526272829303132333435363738394041ysql> create database test; Query OK, 1 row affected (0.14 sec) mysql> use test; Database changed mysql> show tables; Empty set (0.00 sec) mysql> create table test(id int); Query OK, 0 rows affected (0.04 sec) mysql> insert into test values(1); Query OK, 1 row affected (0.01 sec) slave1,slave2上查看是否同步过去 mysql> show databases; +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | | test | +-+5 rows in set (0.00 sec)?12345678910111213141516171819202122232425262728293031323334353637mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +-+ | Tables_in_test | +-+ | test | +-+ 1 row in set (0.00 sec) mysql> select * from test; +-+ | id | +-+ | 1 | +-+ 1 row in set (0.00 sec) mysql>至此mha 主从同步配置成功