安装2台mysql
主从库增加配置
- 主库增加配置
log-bin=/var/lib/mysql/binlog
server-id=1
binlog-do-db = cmdb
#replicate-do-db=cmdb
#replicate_wild_do_table = abc.%
- 从库配置
server-id=2 #于主库不相同即可
主库创建同步用户并查看master值
GRANT REPLICATION SLAVE ON . to 'repl1'@'%' identified by '123456';
show master status;
+------------------+----------+--------------+---------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+---------------------------------------------+-------------------+
| mysql-bin.000028 | 328251 | | mysql,information_schema,performance_schema | |
+------------------+----------+--------------+---------------------------------------------+-------------------+
1 row in set (0.02 sec)
从库配置主从同步
change master to master_host='10.215.33.78',master_port=3306,master_user='repl1',master_password='123456',master_log_file='mysql-bin.000001', master_log_pos=1022;
- 查看主从状态
show slave status\G;