测试MySQL的replaction配置(V5.5)

一、my.cnf配置

master机192.168.112.129的my.cnf配置:

server-id       = 1

slave机192.168.112.130的my.cnf配置
server-id       = 2
read-only = 1
log-slave-updates
#指定同步数据库
replicate-do-db=mytest
#重命名同步日志文件名
relay-log = slave-relay
#重命名同步日志索引文件名
relay-log-index = slave-relay.index
二、启动
(1)启动master与slave的mysql服务
(2)将master上的mytest库导出再导入到slave上
(3)在master机上的mysql命令行下运行show master status;
mysql> show master status;
+——————+———-+————–+——————+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+————–+——————+
| mysql-bin.000004 |     2171 |              |                  |
+——————+———-+————–+——————+
1 row in set (0.00 sec)
(4)在slave机上进入mysql命令行,运行:
change master to master_host=”192.168.112.129″,master_user=”testuser”,master_password=”密码”,master_log_file=”mysql-bin.000004″,master_log_pos=”2171″;
slave start;
show slave status\G;
结果显示:
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.112.129
Master_User: teeume
Master_Port: 43306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 2171
Relay_Log_File: slave-relay-bin.000004
Relay_Log_Pos: 835
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: mytest
Replicate_Ignore_DB:
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: 2171
Relay_Log_Space: 991
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的mytest库的某个表增、改、删除记录,再到slave的mytest库相应表中查可发现表记录与master一致。
replaction同步是根据master的日志来同步的,因此slave需要指定master_log_file(从哪个日志开始同步)及master_log_pos(从日志的哪个位置开始同步)。


相关评论

暂无评论

我要评论