搜尋
首頁資料庫mysql教程 MySQL 5.6 Replication

打开mysql主页,满篇介绍mysql5.6版本有多好,多牛。后来浏览了5.6的更新说明,说是强化了replication,还有人测试开启replication对性能影响不大,不像以前,影

   打开mysql主页,满篇介绍mysql5.6版本有多好,多牛。后来浏览了5.6的更新说明,说是强化了replication,还有人测试开启replication对性能影响不大,不像以前,影响性能明显。反而性能更好?那个叫mysql中国的网站测试说的。官网有说多线程啥的进行复制,好吧。我信了。

   但是安装网上老的配置方法配置主从模式失败,服务器空间,服务起不来,说找不到pid什么文件,错误已经忘啦~~不好意思。

   于是乎,在官方下载最新的安装文档...全英文...一口一口的啃。

   终于在1个小时前配置好了,是双主互备模式。master==master.


   整理下配置方法。


   安装mysql5.6.9(源码下载那个网站没有提供最新的5.6.10版本,而我又不想装RPM包,你懂的)。安装在这里略过,只要看解压后里面的INSTALL文件安装提示来就可以了。


   我把mysql安装到了/usr/local/mysql目录,装完之后,有个my.cnf在/usr/local/mysql目录下面。


   这个就是配置文件了,打开一看,里面就有一行...


-----------------下面我们开始配置-------------


   两台服务器:mysql-m1    192.168.0.140

              mysql-m2    192.168.0.141



   打开mysql-m1的my.cnf文件,添加如下代码:


binlog-format=ROW

   log-slave-updates=true

   gtid-mode=on        # GTID only

   enforce-gtid-consistency=true   # GTID only

   master-info-repository=TABLE

   relay-log-info-repository=TABLE

   sync-master-info=1

   slave-parallel-workers=2

   binlog-checksum=CRC32

   master-verify-checksum=1

   slave-sql-verify-checksum=1

   binlog-rows-query-log_events=1

server-id=1

   report-port=3306

   port=3306

   log-bin=binlog

   report-host=192.168.0.140


肯定有人好奇,为啥要加这些代码?

好吧,我也不知道,官方就这么说的。(开玩笑了)。我把个个参数的意思原汁原味的写出来:

•  binlog-format: row-based replication is selected in order to test all of the MySQL 5.6

optimisations

•  log-slave-updates, gtid-mode, enforce-gtid-consistency, report-port and

report-host: used to enable Global Transaction IDs and meet the associated prerequisites

•  master-info-repository and relay-log-info-repository: are turned on to enable

the crash-safe binlog/slave functionality (storing the information in transactional tables rather

than flat files)

•  sync-master-info: set to 1 to ensure that no information is lost

•  slave-parallel-workers: sets the number of parallel threads to be used for applying

received replication events when this server acts as a slave. A value of 0 would turn off the

multithreaded slave functionality; if the machine has a lot of cores and you are using many

databases within the server then you may want to increase this value in order to better exploit

multi-threaded replication

•  binlog-checksum,  master-verify-checksum  and slave-sql-verify-checksum:

used to enable all of the replication checksum checks

•  binlog-rows-query-log-events: enables informational log events (specifically, the

original SQL query) in the binary log when using row-based replication –  this  makes

troubleshooting simpler

•  log-bin: The server cannot act as a replication master unless binary logging is enabled. If

you wish to enable a slave to assume the role of master at some point in the future (i.e. in the

event of a failover or switchover), you also need to configure binary logging. Binary logging

must also be enabled on the slave(s) when using Global Transaction IDs.

•  server-id: The server_id variable must be unique amongst all servers in the replication

topology and is represented by a positive integer value from 1 to 2

32


好了,上面的参数都知道什么意思了吧。


接下来,我们同样设置第二台服务器:


binlog-format=ROW

log-slave-updates=true

gtid-mode=on        # GTID only

enforce-gtid-consistency=true   # GTID only

master-info-repository=TABLE

relay-log-info-repository=TABLE

sync-master-info=1

slave-parallel-workers=2

binlog-checksum=CRC32

master-verify-checksum=1

slave-sql-verify-checksum=1

binlog-rows-query-log_events=1

server-id=2

report-port=3306

port=3306

log-bin=binlog

report-host=192.168.0.141

注意,server-id=2,另外,report-host也改下。


这两个配置文件改好之后重启服务器。


重启完服务器之后,登录第二台服务器mysql-m2

登录mysql

mysql -u root -p


输入完用户名和密码之后:


> CHANGE MASTER TO MASTER_HOST=192.168.0.140, MASTER_USER='repl_user',

MASTER_PASSWORD='billy';


> START SLAVE;


这样主从模式就做好了主-----》从


-----------------------------------

我们在第一台服务器上设置可远程登录账户:

先登录mysql服务器:

>Grant all privileges on *.* to 'admin'@'%' identified by '123456' with grant option;

红色字体分别为账户和密码。

同样的,第二台服务器也这么操作。


然后,我们在主服务器(mysql-m1)的test数据库下面建立一个表测试同步情况:

登录mysql服务器:mysql -u root -p

>use test;(装好后,mysql默认自带)。

>create table abc(a int,b int,c int);


创建好后插入数据。

>insert into abc values(1,2,3);

多执行几次

然后select * from abc;

查看数据插入进去了没有。(我后面有自己插入了几行)。


mysql> select * from acc;

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

| a    | b    | c    |

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

|    1 |    2 |    3 |

|    1 |    2 |    3 |

|    1 |    2 |    3 |

|    1 |    2 |    3 |

|    1 |    2 |    3 |

|    1 |    2 |    3 |

|    2 |    2 |    2 |

|    2 |    2 |    2 |

|    2 |    2 |    2 |

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

登录mysql-m2,查看是否有数据同步过来。

同步过来了就是ok的了。


-------------------------------------

官方的文档只说了主从模式,我查了一下,要做双主模式,必须开启log-slave-updates=true这个选项。


我看了看两台服务器的配置文件都有这个。


然后呢,我自己试了一下。


登录主服务器---mysql-m1


登录mysql  ----mysql -u root -p

输入密码


执行:

> CHANGE MASTER TO MASTER_HOST=192.168.0.141, MASTER_USER='admin',

MASTER_PASSWORD='123456';


> START SLAVE;



没想到,真的就可以,没报错。


>show slave status\G;


两台服务器都能查询出来信息。


===================总结=================

官方这个文档我是明白了。

它让每个slave都有当master的机会,如果一个master宕机了,

执行:

> CHANGE MASTER TO MASTER_HOST=192.168.0.*, MASTER_USER='repl_user',

MASTER_PASSWORD='billy';


> START SLAVE;

这个操作,只要换个IP地址,可以把任何一台从机变成主机,当主机启动之后,再执行:

> CHANGE MASTER TO MASTER_HOST=192.168.0.MASTER_IP, MASTER_USER='repl_user',

MASTER_PASSWORD='billy';


> START SLAVE;

这样主从切换来回自如。


不过,香港虚拟主机,我真的不知道类似于heartbeat的功能有木有~~~~我不像业务中断,香港虚拟主机,难道要在master上面做heartbeat?



本文出自 “勇攀高峰” 博客,谢绝转载!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
如何向新的MySQL用戶授予權限如何向新的MySQL用戶授予權限May 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

如何在MySQL中添加用戶:逐步指南如何在MySQL中添加用戶:逐步指南May 09, 2025 am 12:14 AM

toadduserInmysqleffect和securly,跟隨台詞:1)USEtheCreateUserStattoDaneWuser,指定thehostandastrongpassword.2)GrantNecterAryAryaryPrivilegesSustherthing privilegesgeStatement,usifementStatement,adheringtotheprinciplelastprefilegege.3)

mysql:添加具有復雜權限的新用戶mysql:添加具有復雜權限的新用戶May 09, 2025 am 12:09 AM

toaddanewuserwithcomplexpermissionsinmysql,loldtheSesteps:1)創建eTheEserWithCreateuser'newuser'newuser'@''localhost'Indedify'pa ssword';。 2)GrantreadAccesstoalltablesin'mydatabase'withGrantSelectOnMyDatabase.to'newuser'@'localhost';。 3)GrantWriteAccessto'

mysql:字符串數據類型和coltrationsmysql:字符串數據類型和coltrationsMay 09, 2025 am 12:08 AM

MySQL中的字符串數據類型包括CHAR、VARCHAR、BINARY、VARBINARY、BLOB、TEXT,排序規則(Collations)決定了字符串的比較和排序方式。 1.CHAR適合固定長度字符串,VARCHAR適合可變長度字符串。 2.BINARY和VARBINARY用於二進制數據,BLOB和TEXT用於大對像數據。 3.排序規則如utf8mb4_unicode_ci忽略大小寫,適合用戶名;utf8mb4_bin區分大小寫,適合需要精確比較的字段。

MySQL:我應該在Varchars上使用什麼長度?MySQL:我應該在Varchars上使用什麼長度?May 09, 2025 am 12:06 AM

最佳的MySQLVARCHAR列長度選擇應基於數據分析、考慮未來增長、評估性能影響及字符集需求。 1)分析數據以確定典型長度;2)預留未來擴展空間;3)注意大長度對性能的影響;4)考慮字符集對存儲的影響。通過這些步驟,可以優化數據庫的效率和擴展性。

mysql blob:有什麼限制嗎?mysql blob:有什麼限制嗎?May 08, 2025 am 12:22 AM

mysqlblobshavelimits:tinyblob(255bytes),blob(65,535 bytes),中間佈洛布(16,777,215個比例),andlongblob(4,294,967,967,295 bytes).tousebl觀察:1)考慮pperformance impactsandSandStorLageBlobSextern; 2)管理backbackupsandreplication carecration; 3)usepathsinst

MySQL:自動化用戶創建的最佳工具是什麼?MySQL:自動化用戶創建的最佳工具是什麼?May 08, 2025 am 12:22 AM

自動化在MySQL中創建用戶的最佳工具和技術包括:1.MySQLWorkbench,適用於小型到中型環境,易於使用但資源消耗大;2.Ansible,適用於多服務器環境,簡單但學習曲線陡峭;3.自定義Python腳本,靈活但需確保腳本安全性;4.Puppet和Chef,適用於大規模環境,複雜但可擴展。選擇時需考慮規模、學習曲線和集成需求。

mysql:我可以在斑點內搜索嗎?mysql:我可以在斑點內搜索嗎?May 08, 2025 am 12:20 AM

是的,YouCansearchInIdeAblobInMysqlusingsPecificteChniques.1)轉換theblobtoautf-8StringWithConvertFunctionWithConvertFunctionandSearchUsiseLike.2)forCompresseBlysBlobs,useuncompresseblobs,useuncompressbeforeconversion.3)expperformance impperformance imptactSandDataEcoding.4)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)