很久之前写过《MySQL 5.1的主从配置》,如今MySQL已经发布了5.6.10,在主从复制功能上做了很多优化,特别是GTID(Global Transact
很久之前写过《MySQL 5.1的主从配置》,如今MySQL已经发布了5.6.10,在主从复制功能上做了很多优化,特别是GTID(Global Transaction ID)的引入, 值得再重新写一篇文章介绍如何配置MySQL 5.6.10的主从复制。
相关阅读:
MySQL 5.6主从复制第一部分[简介及配置]
MySQL 5.6主从复制第二部分[恢复某一台从服务器]
MySQL 5.6主从复制第三部分[把从服务器提升为主服务器]
MySQL 5.6主从复制第四部分[一些被忽视的操作细节]
MySQL 主从复制事件校验 MySQL Replication Event Checksum
使用pt-table-checksum检查主从复制是否正常
----------------------------------------分割线----------------------------------------
还是用mysql::sandbox来测试吧。
主服务器(别名black)安装在 /home/modify/sandboxes/msb_5_6_10/ 使用5610端口。
从服务器(别名blue)安装在 /home/modify/sandboxes/msb_5_6_10_a/ 使用5611端口。
第一步,修改配置文件
修改主服务器配置文件my.sandbox.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=5610
port=5610
log-bin=black-bin.log
report-host=black
innodb_flush_log_at_trx_commit=1
sync_binlog=1
修改从服务器配置文件,添加下面几行:
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=5611
port=5611
log-bin=blue-bin.log
report-host=blue
innodb_flush_log_at_trx_commit=1
sync_binlog=1
可以看到主与从的配置文件基本上是相同的,这样也便于在主服务器挂掉的时候,不用修改配置文件即可把从服务器提升为主。
下面简单介绍每一行的含义:
binlog-format
采用了row-based, 传说5.6对row-based replication做了优化,具体不明。
gtid-mode与enforce-gtid-consistency
决定使用gtid。
传统方式下,主从是基于master binary logfile 与 binary logfile postition的,
当主服务器挂掉,需要把某个从服务器提升为主的时候,需要做很多工作,
主要原因还是在于主从复制其实是异步的,
导致多台从服务器间的数据不一致,有的同步速度快,,有的速度慢, 很有可能每一台从服务器上面的Read_Master_Log_Pos都是不同的。
首先要根据Read_Master_Log_Pos来确定每台从服务器缺少binlog中的哪些transactions(evens),帮它们补充完之后,
从服务器间的数据完全一致了,然后才能把任意一台从服务器提升为主。
这个过程,人工做起来实在是比较痛苦,还好有一些开源的第三方程序可以自动做到,比如MHA。

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools
