mysql异步复制
主服务器:192.168.1.101:5000
从服务器:192.168.1.102:5000
修改主服务器的配置文件:
log-bin=basedb-bin
server-id=1
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=information_schema
replicate-ignore-db=mysql
replicate-ignore-db=performance_schema
replicate-ignore-db=information_schema
指定了database,不在复制处理范围之内。
重启服务器。
创建用于复制的帐号、以及给这个帐号赋权:
grant replication client,replication slave on *.* to repl@192.168.1.102 identified by 'repl123' ;
flush privileges;
指定repl这个用户只能从192.168.1.102这个服务器登录。
show master status;
mysql> show master status;
+-------------------+----------+--------------+---------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+---------------------------------------------+-------------------+
| acctdb-bin.000002 | 205 | | mysql,performance_schema,information_schema | |
+-------------------+----------+--------------+---------------------------------------------+-------------------+
1 row in set (0.00 sec)
配置从服务器
修改配置文件:
relay-log=acctdb-relay-bin
relay-log-index=acct-relay-bin.index
replicate-ignore-db=mysql
replicate-ignore-db=performance_schema
replicate-ignore-db=information_schema
server-id=2
配置从服务器的关于制定主服务的相关信息,不需要修改配置文件,可以直接通过SQL语句配置:
change master to master_host='192.168.1.101', master_user='repl',master_password='repl123',master_port=5000;
启动Slave:start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.101
Master_User: repl
Master_Port: 5000
Connect_Retry: 60
Master_Log_File: acctdb-bin.000002
Read_Master_Log_Pos: 205
Relay_Log_File: acctdb-relay-bin.000003
Relay_Log_Pos: 369
Relay_Master_Log_File: acctdb-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql,performance_schema,information_schema
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 205
Relay_Log_Space: 1037
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: 1
Master_UUID: bc77d75d-1575-11e3-8ecc-742c7ef44da4
Master_Info_File: /home/data/acctdb/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
ERROR:
No query specified
无需指定master_log_file和Read_Master_Log_Pos。