版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sun_ashe/article/details/82152512
简介
本文接上一篇文章,[Replication基础(一) MySQL数据库单机多实例安装][1]
在已经存在的单机多实例环境中搭建主从复制,假设以13307端口的实例为主机,13308端口的实例为从机,搭建主从复制。
步骤
- 在主库上创建复制账号,从机使用此账号进行复制链接。如下:
grant replication slave,replication client on *.* to 'rpl'@'%' identified by 'rpl';
- 从机通过
change master
命令填充复制信息
mysql> change master to
-> master_host='127.0.0.1',
-> master_port=13307,
-> master_user='rpl',
-> master_password='rpl',
-> master_auto_position=1
-> for channel 'master_13307';
Query OK, 0 rows affected, 2 warnings (0.04 sec)
- 启动复制
start slave;
- 查看复制状态
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: rpl
Master_Port: 13307
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 456
Relay_Log_File: mysql-relay-bin-master_13307.000002
Relay_Log_Pos: 669
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table: mysql.ibbackup_binlog_marker
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table: mysql.backup_%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 456
Relay_Log_Space: 889
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 12713307
Master_UUID: 08abd9a8-a5e9-11e8-bcc6-000c29fc1d1b
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 08abd9a8-a5e9-11e8-bcc6-000c29fc1d1b:1
Executed_Gtid_Set: 08abd9a8-a5e9-11e8-bcc6-000c29fc1d1b:1
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name: master_13307
Master_TLS_Version:
1 row in set (0.00 sec)
结束语
然后就可以在主库上执行操作,看看从机是否同步了。