海淀区玉泉小学网站 建设方/seo收录查询
简介
本文接上一篇文章,[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 eventMaster_Host: 127.0.0.1Master_User: rplMaster_Port: 13307Connect_Retry: 60Master_Log_File: mysql-bin.000001Read_Master_Log_Pos: 456Relay_Log_File: mysql-relay-bin-master_13307.000002Relay_Log_Pos: 669Relay_Master_Log_File: mysql-bin.000001Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table: mysql.ibbackup_binlog_markerReplicate_Wild_Do_Table:Replicate_Wild_Ignore_Table: mysql.backup_%Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 456Relay_Log_Space: 889Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error:Last_SQL_Errno: 0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id: 12713307Master_UUID: 08abd9a8-a5e9-11e8-bcc6-000c29fc1d1bMaster_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind:Last_IO_Error_Timestamp:Last_SQL_Error_Timestamp:Master_SSL_Crl:Master_SSL_Crlpath:Retrieved_Gtid_Set: 08abd9a8-a5e9-11e8-bcc6-000c29fc1d1b:1Executed_Gtid_Set: 08abd9a8-a5e9-11e8-bcc6-000c29fc1d1b:1Auto_Position: 1Replicate_Rewrite_DB:Channel_Name: master_13307Master_TLS_Version:
1 row in set (0.00 sec)
结束语
然后就可以在主库上执行操作,看看从机是否同步了。