天天看點

a-b1 a-b2

Master:

修改配置檔案:/etc/my.cnf

[root@localhost ~]# vim /etc/my.cnf

[mysqld]

log-bin=binlog

log-bin-index=binlog.index

sync_binlog=0

server_id = 1

重新開機mysql:

[root@localhost ~]# /etc/init.d/mysqld restart

停止 MySQL:                                               [确定]

啟動 MySQL:                                               [确定]

[root@localhost ~]#

Slave1:

server_id = 2

relay_log = /var/lib/mysql/mysql-relay-bin

relay_log_index=/var/lib/mysql/mysql-relay-bin.index

Slave2:

server_id = 3

Master:

[root@localhost ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.0.77-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> GRANT replication slave ON *.* TO 'ab'@'%' identified by '123';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

[root@localhost ~]# cd /var/lib/mysql/

[root@localhost mysql]# ls

ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock test

[root@localhost mysql]# rm -rf *

[root@localhost mysql]# /etc/init.d/mysqld restart

[root@localhost ~]# mysqldump -A -x > /tmp/full.sql

[root@localhost ~]# scp /tmp/full.sql [email protected]:/tmp/

The authenticity of host '192.168.18.117 (192.168.18.117)' can't be established.

RSA key fingerprint is 1f:ce:39:33:61:f5:7d:f8:0b:89:c7:d8:06:46:79:1f.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.18.117' (RSA) to the list of known hosts.

[email protected]'s password:

full.sql                                      100% 1039MB   4.8MB/s   03:35   

[root@localhost mysql]# mysql < /tmp/full.sql

mysql> flush tables with read lock;

mysql> show master status;

+---------------+----------+--------------+------------------+

| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |

| binlog.000003 |      365 |              |                  |

1 row in set (0.03 sec)

mysql> unlock tables;

Query OK, 0 rows affected (0.03 sec)

mysql> change master to master_host='192.168.18.107', master_port=3306, master_user='ab', master_password='123', master_log_file='binlog.000003',master_log_pos=365;

Query OK, 0 rows affected (0.06 sec)

mysql> start slave;

mysql> show slave status \G

<b>Slave_IO_Running: Yes</b>

<b>Slave_SQL_Running: Yes</b>

[root@localhost ~]# mysqldump -A -x &gt; /tmp/mysql.sql

[root@localhost ~]# scp /tmp/mysql.sql [email protected]:/tmp/

The authenticity of host '192.168.18.127 (192.168.18.127)' can't be established.

RSA key fingerprint is f7:a5:9e:2f:86:57:a5:17:f4:ad:2b:3a:a8:55:0f:76.

Warning: Permanently added '192.168.18.127' (RSA) to the list of known hosts.

[email protected]'s password:

mysql.sql                                     100% 1039MB 20.8MB/s   00:50   

[root@localhost mysql]#

<b> </b>

[root@localhost mysql]# mysql &lt; /tmp/mysql.sql

1 row in set (0.00 sec)

Query OK, 0 rows affected (0.05 sec)

mysql&gt; show slave status \G

測試:

Master slave1 slave2

mysql&gt; show databases;

+--------------------+

| Database           |

| information_schema |

| mysql              |

| test               |

| ww                 |

4 rows in set (0.00 sec)

mysql&gt;

mysql&gt; drop database ww;

Query OK, 1 row affected (0.09 sec)

3 rows in set (0.00 sec)

測試後可看出,slave1 ,slave2同步成功。

ASA