MySQL雙Master設置裝備擺設的辦法詳解。本站提示廣大學習愛好者:(MySQL雙Master設置裝備擺設的辦法詳解)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL雙Master設置裝備擺設的辦法詳解正文
方才抽閒做了一下MYSQL 的主主同步。
把步調寫上去,至於會湧現的甚麼成績,今後隨時更新。這裡我同步的數據庫是TEST
1、情況描寫。
主機:192.168.0.231(A)
主機:192.168.0.232(B)
MYSQL 版本為5.1.21
2、受權用戶。
A:
mysql> grant replication slave,file on *.* to 'repl1'@'192.168.0.232' identified
by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
B:
mysql> grant replication slave,file on *.* to 'repl2'@'192.168.0.231' identified
by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
然後都停滯MYSQL 辦事器。
3、設置裝備擺設文件。
在兩個機械上的my.cnf外面都開啟二進制日記 。
A:
user = mysql
log-bin=mysql-bin
server-id = 1
binlog-do-db=test
binlog-ignore-db=mysql
replicate-do-db=test
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
skip-name-resolvesync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
B:
user = mysql
log-bin=mysql-bin
server-id = 2
binlog-do-db=test
binlog-ignore-db=mysql
replicate-do-db=test
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
skip-name-resolvesync_binlog=1
auto_increment_increment=2
auto_increment_offset=2
至於這些參數的解釋詳細看手冊。
白色的部門異常主要,假如一個MASTER 掛失落的話,別的一個立時接收。
紫白色的部門指的是辦事器頻仍的刷新日記。這個包管了在個中一台掛失落的話,日記刷新到別的一台。從而包管了數據的同步 。
4、從新啟動MYSQL辦事器。
在A和B上履行雷同的步調
[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe &
[1] 4264
[root@localhost ~]# 071213 14:53:20 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
/usr/local/mysql/bin/mysqld_safe: line 366: [: -eq: unary operator expected
071213 14:53:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
5、進入MYSQL的SHELL。
A:
mysql> flush tables with read lock\G
Query OK, 0 rows affected (0.00 sec)
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000007
Position: 528
Binlog_Do_DB: test
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
B:
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000004
Position: 595
Binlog_Do_DB: test
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
然後備份本身的數據,堅持兩個機械的數據分歧。
辦法許多。完了後看下一步。
6、在各自機械上履行CHANGE MASTER TO敕令。
A:
mysql> change master to
-> master_host='192.168.0.232',
-> master_user='repl2',
-> master_password='123456',
-> master_log_file='mysql-bin.000004',
-> master_log_pos=595;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
B:
mysql> change master to
-> master_host='192.168.0.231',
-> master_user='repl1',
-> master_password='123456',
-> master_log_file='mysql-bin.000007',
-> master_log_pos=528;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
7、檢查各自機械上的IO過程和 SLAVE過程能否都開啟。
A:
mysql> show processlist\G
*************************** 1. row ***************************
Id: 2
User: repl
Host: 192.168.0.232:54475
db: NULL
Command: Binlog Dump
Time: 1590
State: Has sent all binlog to slave; waiting for binlog to be updated
Info: NULL
*************************** 2. row ***************************
Id: 3
User: system user
Host:
db: NULL
Command: Connect
Time: 1350
State: Waiting for master to send event
Info: NULL
*************************** 3. row ***************************
Id: 4
User: system user
Host:
db: NULL
Command: Connect
Time: 1149
State: Has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
*************************** 4. row ***************************
Id: 5
User: root
Host: localhost
db: test
Command: Query
Time: 0
State: NULL
Info: show processlist
4 rows in set (0.00 sec)
B:
mysql> show processlist\G
*************************** 1. row ***************************
Id: 1
User: system user
Host:
db: NULL
Command: Connect
Time: 2130
State: Waiting for master to send event
Info: NULL
*************************** 2. row ***************************
Id: 2
User: system user
Host:
db: NULL
Command: Connect
Time: 1223
State: Has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
*************************** 3. row ***************************
Id: 4
User: root
Host: localhost
db: test
Command: Query
Time: 0
State: NULL
Info: show processlist
*************************** 4. row ***************************
Id: 5
User: repl2
Host: 192.168.0.231:50718
db: NULL
Command: Binlog Dump
Time: 1398
State: Has sent all binlog to slave; waiting for binlog to be updated
Info: NULL
4 rows in set (0.00 sec)
假如白色部門沒有湧現,檢討DATA目次下的毛病文件。
8、釋放失落各自的鎖,然落後行插數據測試。
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
拔出之前兩個機械表的比較:
A:
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t11_innodb |
| t22 |
+----------------+
B:
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t11_innodb |
| t22 |
+----------------+
從A機械長進行拔出
A:
mysql> create table t11_replicas
-> (id int not null auto_increment primary key,
-> str varchar(255) not null) engine myisam;
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t11_replicas(str) values
-> ('This is a master to master test table');
Query OK, 1 row affected (0.01 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t11_innodb |
| t11_replicas |
| t22 |
+----------------+
3 rows in set (0.00 sec)
mysql> select * from t11_replicas;
+----+---------------------------------------+
| id | str |
+----+---------------------------------------+
| 1 | This is a master to master test table |
+----+---------------------------------------+
1 row in set (0.00 sec)
如今來看B機械:
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t11_innodb |
| t11_replicas |
| t22 |
+----------------+
3 rows in set (0.00 sec)
mysql> select * from t11_replicas;
+----+---------------------------------------+
| id | str |
+----+---------------------------------------+
| 1 | This is a master to master test table |
+----+---------------------------------------+
1 row in set (0.00 sec)
如今反過去從B機械上拔出數據:
B:
mysql> insert into t11_replicas(str) values('This is a test 2');
Query OK, 1 row affected (0.00 sec)
mysql> select * from t11_replicas;
+----+---------------------------------------+
| id | str |
+----+---------------------------------------+
| 1 | This is a master to master test table |
| 2 | This is a test 2 |
+----+---------------------------------------+
2 rows in set (0.00 sec)
我們來看A
A:
mysql> select * from t11_replicas;
+----+---------------------------------------+
| id | str |
+----+---------------------------------------+
| 1 | This is a master to master test table |
| 2 | This is a test 2 |
+----+---------------------------------------+
2 rows in set (0.00 sec)
好了。如今兩個表相互為MASTER。