单向备份,从192.168.1.122向192.168.1.166备份ets_door数据库

【服务端】192.168.1.122
1、在服务器的my.ini中(C:\Program Files (x86)\MySQL\MySQL Server 5.5)的
[mysqld]节点中任意位置,增加如下内容:
server-id=1
log-bin=c:\mysqlback
binlog-do-db=ets_door
sync_binlog=1

其中,以上配置中server-id、binlog-do-db是必须的

2、创建用户并授权
在MySQL 5.5 Command Line Client的命令提示行,执行以下命令:
grant replication slave on *.* to 'backup'@'192.168.1.166' identified by '000000';

其中,
replication slave表示授权从服务器复制
backup表示给服务器上创建用户名,相当于root用户
000000是对应的密码

3、锁定表
mysql> flush tables with read lock;

mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysqlback.000005 | 1602 | ets_door | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

客户端设置完成之后,执行:
mysql> unlock tables;

4、备份服务器数据库,还原到客户端对应数据库,即表数量、结构、数据完全一致。

【客户端】192.168.1.166
1、复制数据文件,将master服务器上的data文件夹,复制到slave中对应的文件夹(没有测试是否必须)
C:\Program Files (x86)\MySQL\MySQL Server 5.5\data

2、在客户端的my.ini中(C:\Program Files (x86)\MySQL\MySQL Server 5.5)的
[mysqld]节点中任意位置,增加如下内容:
log_bin=mysql-bin
server_id=2
relay_log=mysql-relay-bin
log_slave_updates=1
read_only=1
replicate-do-db=ets_door

其中,以上配置中server-id、binlog-do-db是必须的

3、执行如下命令:
mysql> stop slave;


CHANGE MASTER TO MASTER_HOST='10.177.1.132',MASTER_USER='backup',MASTER_PASSWORD='etsSoftCER',MASTER_PORT=3306,MASTER_LOG_FILE='mysqlback.000004',MASTER_LOG_POS=29931;

mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.122',MASTER_USER='backup',MASTER_PASSWORD='000000',MASTER_PORT=3306,MASTER_LOG_FILE='mysqlback.000005',MASTER_LOG_POS=1602;
Query OK, 0 rows affected (0.44 sec)

如果上一条change执行失败,可以执行如下reset或其他
mysql> reset slave;

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

4、显示从服务器的状态

mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.122
Master_User: backup
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqlback.000005
Read_Master_Log_Pos: 1602
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 253
Relay_Master_Log_File: mysqlback.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: ets_door
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: 1602
Relay_Log_Space: 409
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
1 row in set (0.00 sec)


【操作实验】
在192.168.1.122的ets_door数据库中修改数据,观察192.168.1.166的ets_door数据库的数据变化