(六)配置从服务器
mysql> change master to master_host='192.168.8.101', master_user='rep1', master_password='mysql', master_log_file='mysql-bin.000003', master_log_pos=235;
正确执行后再执行:
mysql> start slave;
就启用了复制功能.这里我们运行一下 mysql> show slave status\G 来检查一下,一个正常的输出结果应该如下面的形式:
1 mysql> show slave status\G
2 *************************** 1. row ***************************
3 Slave_IO_State: Waiting for master to send event
4 Master_Host: 192.168.8.101
5 Master_User: rep1
6 Master_Port: 3306
7 Connect_Retry: 60
8 Master_Log_File: mysql-bin.000003
9 Read_Master_Log_Pos: 235
10 Relay_Log_File: -relay-bin.000009
11 Relay_Log_Pos: 235
12 Relay_Master_Log_File: mysql-bin.000003
13 Slave_IO_Running: Yes
14 Slave_SQL_Running: Yes
15 Replicate_Do_DB:
16 Replicate_Ignore_DB:
17 Replicate_Do_Table:
18 Replicate_Ignore_Table:
19 Replicate_Wild_Do_Table:
20 Replicate_Wild_Ignore_Table:
21 Last_Errno: 0
22 Last_Error:
23 Skip_Counter: 0
24 Exec_Master_Log_Pos: 235
25 Relay_Log_Space: 235
26 Until_Condition: None
27 Until_Log_File:
28 Until_Log_Pos: 0
29 Master_SSL_Allowed: No
30 Master_SSL_CA_File:
31 Master_SSL_CA_Path:
32 Master_SSL_Cert:
33 Master_SSL_Cipher:
34 Master_SSL_Key:
35 Seconds_Behind_Master: 0
36 1 row in set (0.00 sec)
2 *************************** 1. row ***************************
3 Slave_IO_State: Waiting for master to send event
4 Master_Host: 192.168.8.101
5 Master_User: rep1
6 Master_Port: 3306
7 Connect_Retry: 60
8 Master_Log_File: mysql-bin.000003
9 Read_Master_Log_Pos: 235
10 Relay_Log_File: -relay-bin.000009
11 Relay_Log_Pos: 235
12 Relay_Master_Log_File: mysql-bin.000003
13 Slave_IO_Running: Yes
14 Slave_SQL_Running: Yes
15 Replicate_Do_DB:
16 Replicate_Ignore_DB:
17 Replicate_Do_Table:
18 Replicate_Ignore_Table:
19 Replicate_Wild_Do_Table:
20 Replicate_Wild_Ignore_Table:
21 Last_Errno: 0
22 Last_Error:
23 Skip_Counter: 0
24 Exec_Master_Log_Pos: 235
25 Relay_Log_Space: 235
26 Until_Condition: None
27 Until_Log_File:
28 Until_Log_Pos: 0
29 Master_SSL_Allowed: No
30 Master_SSL_CA_File:
31 Master_SSL_CA_Path:
32 Master_SSL_Cert:
33 Master_SSL_Cipher:
34 Master_SSL_Key:
35 Seconds_Behind_Master: 0
36 1 row in set (0.00 sec)
请注意:slave_IO进程及slave_SQL进程都必须正常运行,在状态输出重表现为: Slave_IO_Running: Yes 及Slave_SQL_Running: Yes否则都是不正确的状态(如一个值Yes,另外一个是NO则不行).
(七)主数据库有数据的情况:
1、数据库锁表操作,不让数据再进行写入动作。mysql> FLUSH TABLES WITH READ LOCK;
2、察看主数据库的状态 mysql> show master status; 照第(五)步记录输出值。
3、把主服务器数据文件复制到从服务器,最好先用tar处理一下。
4、取消主数据库锁定 mysql> UNLOCK TABLES;
5、从服务器的操作。跟前面的步骤一样(略过)