bitsCN.com
mysql_upgrade引起的master/slave replication中断解决
在生产环境master服务器上处理完《1548-Cannot loadfrom mysql.proc. The table is probably corrupted》后,接到报警信息,slave服务器复制中断查看slave 状态
mysql>show slave status
发现如下语句执行错误
DROP DATABASEIF EXISTS performance_schema
performance_schema是mysql自带的性能信息相关的库,mysql怎么会执行这个操作,看看错误日志吧
[root@db25522]# tail -n 500/data/my2/mysql/db25522.err
13051310:29:54 [Note] Error reading relay log event: slave SQL thread was killed
13051310:29:54 [ERROR] Error reading packet from server: Lost connection to MySQLserver during query ( server_errno=2013)
13051310:29:54 [Note] Slave I/O thread killed while reading event
13051310:29:54 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.002734',position 1017737307
13051310:29:57 [Note] Slave I/O thread: connected to master 'repl@xxx.xxx.xxx.xxx:3306',replicationstarted in log 'mysql-bin.002734' at position 1017737307
13051310:29:57 [Note] Slave SQL thread initialized, starting replication in log'mysql-bin.002734' at position 1017729051, relay log'/my/rlog/relay-bin.000764' position: 1017729197
13053015:00:53 [ERROR] Incorrect definition of table mysql.proc: expected column'comment' at position 15 to have type text, found type char(64).
13053015:00:53 [ERROR] Slave SQL: Query caused differenterrors on master and slave. Error on master: message (format)='Cannot load from mysql.%s. The tableis probably corrupted' error code=1548 ; Error on slave: actual message='noerror', error code=0. Default database: 'performance_schema'. Query: 'DROP DATABASE IF EXISTS performance_schema',Error_code: 0
13053015:00:53 [Warning] Slave: Cannot load from mysql.proc. The table is probablycorrupted Error_code: 1548
13053015:00:53 [ERROR] Error running query, slave SQL thread aborted. Fix theproblem, and restart the slave SQL thread with "SLAVE START". We stoppedat log 'mysql-bin.002947' position 721651903
莫非是数据不一致导致的?发现master服务器有performance_schema这个库,但是slave服务器没有。在执行 mysql_upgrade -uroot 之前,主从复制在运行,判断操作发生在mysql_upgrade-uroot之后,分析master上日志,在这个时间段内mysql进行了那些操作
[root@db25522]# mysqlbinlog --no-defaults --start-date='2013-05-3015:00:00' --end-date='2013-05-3015:03:00' mysql-bin.002947 >/root/tmp.log
查询日志发现
[root@db25522]#vi /root/tmp.log
/DROP
/*!*/;
# at721651876
#13053015:00:25 server id 13084 end_log_pos721651903 Xid = 435509540
COMMIT/*!*/;
# at 721651903
#13053015:00:53 server id 13084 end_log_pos721652022 Query thread_id=418930 exec_time=0 error_code=1548
SETTIMESTAMP=1369897253/*!*/;
/*!/Cutf8 *//*!*/;
SET@@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=28/*!*/;
DROP DATABASE IF EXISTS performance_schema
/*!*/;
# at721652022
#13053015:00:53 server id 13084 end_log_pos721652152 Query thread_id=418930 exec_time=0 error_code=0
SETTIMESTAMP=1369897253/*!*/;
CREATEDATABASE performance_schema character set utf8
/*!*/;
# at721652152
#13053015:03:19 server id 13084 end_log_pos721652223 Query thread_id=418956 exec_time=0 error_code=0
SETTIMESTAMP=1369897399/*!*/;
/*!/Cgbk *//*!*/;
SET@@session.character_set_client=28,@@session.collation_connection=28,@@session.collation_server=28/*!*/;
BEGIN
/*!*/;
# at721652223
#13053015:03:19 server id 13084 end_log_pos721652336 Query thread_id=418956 exec_time=0 error_code=0
usePriceDB/*!*/;
SETTIMESTAMP=1369897399/*!*/;
好吧,上面红色部分,执行了这个操作,再看看slave错误日志
13053015:00:53 [错误]表 mysql.proc 的定义不正确:预期位置 15 处的列“comment”具有文本类型,发现类型为 char(64)。
13053015:00:53 [错误] 从属 SQL:查询在主从服务器上导致不同的错误。 主服务器上的错误:消息(格式)='无法从 mysql 加载。%s。该表可能已损坏' errorcode=1548 ;从站错误:实际消息=“无错误”,错误代码=0。默认数据库:“performance_schema”。查询:'DROP DATABASE IF EXISTSperformance_schema',Error_code:0
13053015:00:53 [警告]从站:无法从 mysql.proc 加载。该表可能已损坏 Error_code: 1548
13053015:00:53 [错误] 运行查询时出错,从属 SQL 线程中止。修复问题,并使用“SLAVE START”重新启动从属 SQL 线程。我们停在log 'mysql-bin.002947'位置721651903
5.5的日志错误还是很人性化的,slave时停止读取的binlog日志文件,位置很清楚。为我们重启slave提供了方便。既然是DROP DATABASE IFEXISTS Performance_schema导致的错误,那就跳过这个事件。
从服务器:
mysql> 显示类似 '%skip%' 的变量;
mysql>setglobal sql_slave_skip_counter =1;
mysql>slave start ;
复制正常
总结:复制虽然正常了。为什么 mysql_upgrade 会做 DROP DATABASE IF EXISTSperformance_schema 这个操作?希望遇到类似问题的朋友,一起交流。
bitsCN.com
mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而alenosqloptionslikemongodb,redis和calablesolutionsoluntionsoluntionsoluntionsolundortionsolunsolunsstructureddata.blobobobsimplobissimplobisslowderperformandperformanceperformancewithlararengelitiate;

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollationsEttingsefectery.1)usecharforfixed lengengters lengengtings,varchar forbariaible lengength,varchariable length,andtext/blobforlabforlargerdata.2 seterters seterters seterters seterters

mysqloffersechar,varchar,text,and denumforstringdata.usecharforfixed Lengttrings,varcharerforvariable长度,文本forlarger文本,andenumforenforcingDataAntegrityWithaEtofValues。

优化MySQLBLOB请求可以通过以下策略:1.减少BLOB查询频率,使用独立请求或延迟加载;2.选择合适的BLOB类型(如TINYBLOB);3.将BLOB数据分离到单独表中;4.在应用层压缩BLOB数据;5.对BLOB元数据建立索引。这些方法结合实际应用中的监控、缓存和数据分片,可以有效提升性能。

掌握添加MySQL用户的方法对于数据库管理员和开发者至关重要,因为它确保数据库的安全性和访问控制。1)使用CREATEUSER命令创建新用户,2)通过GRANT命令分配权限,3)使用FLUSHPRIVILEGES确保权限生效,4)定期审计和清理用户账户以维护性能和安全。

chosecharforfixed-lengthdata,varcharforvariable-lengthdata,andtextforlargetextfield.1)chariseffity forconsistent-lengthdatalikecodes.2)varcharsuitsvariable-lengthdatalikenames,ballancingflexibilitibility andperformance.3)

在MySQL中处理字符串数据类型和索引的最佳实践包括:1)选择合适的字符串类型,如CHAR用于固定长度,VARCHAR用于可变长度,TEXT用于大文本;2)谨慎索引,避免过度索引,针对常用查询创建索引;3)使用前缀索引和全文索引优化长字符串搜索;4)定期监控和优化索引,保持索引小巧高效。通过这些方法,可以在读取和写入性能之间取得平衡,提升数据库效率。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

WebStorm Mac版
好用的JavaScript开发工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器