最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL雙Master配置的方法詳解

 更新時(shí)間:2013年06月18日 10:52:43   作者:  
本篇文章是對(duì)MySQL雙Master配置進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
剛剛抽空做了一下MYSQL 的主主同步。
把步驟寫下來(lái),至于會(huì)出現(xiàn)的什么問題,以后隨時(shí)更新。這里我同步的數(shù)據(jù)庫(kù)是TEST
1、環(huán)境描述。
主機(jī):192.168.0.231(A)
主機(jī):192.168.0.232(B)
MYSQL 版本為5.1.21
2、授權(quán)用戶。
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 服務(wù)器。

3、配置文件。
在兩個(gè)機(jī)器上的my.cnf里面都開啟二進(jìn)制日志 。
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-resolve
sync_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-resolve
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2
至于這些參數(shù)的說(shuō)明具體看手冊(cè)。
紅色的部分非常重要,如果一個(gè)MASTER 掛掉的話,另外一個(gè)馬上接管。
紫紅色的部分指的是服務(wù)器頻繁的刷新日志。這個(gè)保證了在其中一臺(tái)掛掉的話,日志刷新到另外一臺(tái)。從而保證了數(shù)據(jù)的同步 。
4、重新啟動(dòng)MYSQL服務(wù)器。
在A和B上執(zhí)行相同的步驟
[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、進(jìn)入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)
然后備份自己的數(shù)據(jù),保持兩個(gè)機(jī)器的數(shù)據(jù)一致。
方法很多。完了后看下一步。
6、在各自機(jī)器上執(zhí)行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、查看各自機(jī)器上的IO進(jìn)程和 SLAVE進(jìn)程是否都開啟。
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)

如果紅色部分沒有出現(xiàn),檢查DATA目錄下的錯(cuò)誤文件。

8、釋放掉各自的鎖,然后進(jìn)行插數(shù)據(jù)測(cè)試。
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

插入之前兩個(gè)機(jī)器表的對(duì)比:
A:

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t11_innodb     | 
| t22            | 
+----------------+
B:

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t11_innodb     | 
| t22            | 
+----------------+
從A機(jī)器上進(jìn)行插入
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)


現(xiàn)在來(lái)看B機(jī)器:

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)

現(xiàn)在反過來(lái)從B機(jī)器上插入數(shù)據(jù):
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)
我們來(lái)看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)

好了?,F(xiàn)在兩個(gè)表互相為MASTER。

相關(guān)文章

  • Mysql之如何修改字段名和字段類型

    Mysql之如何修改字段名和字段類型

    這篇文章主要介紹了Mysql之如何修改字段名和字段類型問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Mysql8.0密碼問題mysql_native_password和caching_sha2_password詳解

    Mysql8.0密碼問題mysql_native_password和caching_sha2_password詳解

    這篇文章主要介紹了Mysql8.0密碼問題mysql_native_password和caching_sha2_password,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • MySql官方手冊(cè)學(xué)習(xí)筆記2 MySql的模糊查詢和正則表達(dá)式

    MySql官方手冊(cè)學(xué)習(xí)筆記2 MySql的模糊查詢和正則表達(dá)式

    MySQL提供標(biāo)準(zhǔn)的SQL模式匹配,以及擴(kuò)展正則表達(dá)式模式匹配的格式
    2012-10-10
  • MySql實(shí)現(xiàn)分布式鎖詳解

    MySql實(shí)現(xiàn)分布式鎖詳解

    這篇文章主要為大家詳細(xì)介紹了如何使用本地MySql實(shí)現(xiàn)一把分布式鎖,以及Mysql實(shí)現(xiàn)分布式鎖的原理是怎么樣的,有需要的小伙伴可以了解下
    2024-11-11
  • 游戲和服備忘問題簡(jiǎn)析

    游戲和服備忘問題簡(jiǎn)析

    這篇文章主要介紹了游戲和服備忘問題簡(jiǎn)析,小編覺得挺不錯(cuò)的,這里分享給大家,希望給大家一個(gè)參考。
    2017-10-10
  • MySQL數(shù)據(jù)庫(kù)備份以及常用備份工具集合

    MySQL數(shù)據(jù)庫(kù)備份以及常用備份工具集合

    數(shù)據(jù)庫(kù)備份種類按照數(shù)據(jù)庫(kù)大小備份,有四種類型,分別應(yīng)用于不同場(chǎng)合。本文將MySQL 數(shù)據(jù)庫(kù)備份種類以及常用備份工具進(jìn)行匯總,方便大家學(xué)習(xí)。
    2015-08-08
  • MySQL中使用MD5加密的實(shí)現(xiàn)

    MySQL中使用MD5加密的實(shí)現(xiàn)

    本文主要介紹了MySQL中使用MD5加密的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • MySQL?FLOAT不準(zhǔn)問題解析

    MySQL?FLOAT不準(zhǔn)問題解析

    在數(shù)據(jù)庫(kù)處理中,使用FLOAT類型存儲(chǔ)浮點(diǎn)數(shù)時(shí),由于二進(jìn)制表示的限制,會(huì)導(dǎo)致精度損失,解決方法包括使用DOUBLE或DECIMAL類型來(lái)提高精度,或避免使用浮點(diǎn)數(shù)進(jìn)行精確計(jì)算,感興趣的可以了解一下
    2024-09-09
  • MySQL?B-tree與B+tree索引數(shù)據(jù)結(jié)構(gòu)剖析

    MySQL?B-tree與B+tree索引數(shù)據(jù)結(jié)構(gòu)剖析

    這篇文章主要介紹了MySQL?B-tree與B+tree索引數(shù)據(jù)結(jié)構(gòu)剖析,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-08-08
  • MySQL server has gone away的問題解決

    MySQL server has gone away的問題解決

    本文主要介紹了MySQL server has gone away的問題解決,意思就是指client和MySQL server之間的鏈接斷開了,下面就來(lái)介紹一下幾種原因及其解決方法,感興趣的可以了解一下
    2024-07-07

最新評(píng)論

临武县| 孟州市| 潜山县| 黔西县| 韶山市| 化州市| 绿春县| 巴南区| 类乌齐县| 高邑县| 平遥县| 区。| 江门市| 宜春市| 宜君县| 罗田县| 巩义市| 佛教| 广河县| 西畴县| 渝中区| 汉中市| 滕州市| 平利县| 吉林省| 盈江县| 青阳县| 营山县| 新沂市| 古蔺县| 邮箱| 唐海县| 明溪县| 宁明县| 阿合奇县| 隆回县| 彭水| 苍南县| 灵武市| 吉木萨尔县| 宜昌市|