MySQL Shell提供了一套工具集,用户可以利用这套工具集完成不同的MySQL 任务。在这一篇文章里,将为读者介绍升级检查器。
用户可以使用升级检查器来检查MySQL 5.7服务器实例,以及MySQL 8.0服务器实例与最新MySQL 8.0版本的兼容性错误和升级问题。在这里再次强调一下,使用MySQL 5.7的用户,你的MySQL该升级了。按照目前制定的产品生命周期计划,MySQL 5.7在明年10月份之后不再提供任何补丁代码,届时如果遇到安全问题,将会影响到系统的安全性。
升级检查器可以检查服务器实例的配置文件(my.cnf或my.ini)。如果存在现有的配置文件中已经定义,但在目标服务器版本中被删除的任何系统变量,或者现有的配置文件中没有定义,但在目标MySQL服务器版本中具有不同默认值的任何系统变量。升级检查器将列出相关信息。
升级检查器可以生成默认格式的输出,也可以生成JSON格式的输出,使用JSON格式可能更容易进行自动化的解析和处理。
使用该工具时,只需在MySQL Shell中执行:
util.checkForServerUpgrade (ConnectionData connectionData, Dictionary options)
注意选项部分,第一个选项用于提供连接至MySQL实例的信息,第二个选项以字典的形式提供,包括目标版本、配置路径及输出格式等内容。
举一个例子:
MySQL localhost:3310 ssl JS > util.checkForServerUpgrade('root@localhost:3310',{"targetVersion":"8.0.28"})The MySQL server at localhost:3310, version 8.0.20 - MySQL Community Server -GPL, will now be checked for compatibility issues for upgrade to MySQL 8.0.28...1) Issues reported by 'check table x for upgrade' commandNo issues foundErrors: 0Warnings: 0Notices: 0No known compatibility errors or issues were found.
可以看到,从8.0.20升级至8.0.28是不存在不兼容现象的。
再举一个5.7的🌰:
MySQL localhost:3306 JS > util.checkForServerUpgrade('root@localhost:3306',{"targetVersion":"8.0.28"})Please provide the password for 'root@localhost:3306': ****Save password for 'root@localhost:3306'? [Y]es/[N]o/Ne[v]er (default No): yThe MySQL server at localhost:3306, version 5.7.18-log - MySQL Community Server(GPL), will now be checked for compatibility issues for upgrade to MySQL8.0.28...1) Usage of old temporal typeNo issues found2) Usage of db objects with names conflicting with new reserved keywordsNo issues found3) Usage of utf8mb3 charsetNo issues found4) Table names in the mysql schema conflicting with new tables in 8.0No issues found5) Partitioned tables using engines with non native partitioningNo issues found6) Foreign key constraint names longer than 64 charactersNo issues found7) Usage of obsolete MAXDB sql_mode flagNo issues found8) Usage of obsolete sql_mode flagsNotice: The following DB objects have obsolete options persisted forsql_mode, which will be cleared during upgrade to 8.0.More information:https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html#mysql-nutshell-removalsglobal system variable sql_mode - defined using obsolete NO_AUTO_CREATE_USERoption9) ENUM/SET column definitions containing elements longer than 255 charactersNo issues found10) Usage of partitioned tables in shared tablespacesNo issues found11) Circular directory references in tablespace data file pathsNo issues found12) Usage of removed functionsNo issues found13) Usage of removed GROUP BY ASC/DESC syntaxNo issues found14) Removed system variables for error logging to the system log configurationTo run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionaryMore information:https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-13.html#mysqld-8-0-13-logging15) Removed system variablesTo run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionaryMore information:https://dev.mysql.com/doc/refman/8.0/en/added-deprecated-removed.html#optvars-removed16) System variables with new default valuesTo run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionaryMore information:https://mysqlserverteam.com/new-defaults-in-mysql-8-0/17) Zero Date, Datetime, and Timestamp valuesNo issues found18) Schema inconsistencies resulting from file removal or corruptionNo issues found19) Tables recognized by InnoDB that belong to a different engineNo issues found20) Issues reported by 'check table x for upgrade' commandNo issues found21) New default authentication plugin considerationsWarning: The new default authentication plugin 'caching_sha2_password' offersmore secure password hashing than previously used 'mysql_native_password'(and consequent improved client connection authentication). However, it alsohas compatibility implications that may affect existing MySQL installations.If your MySQL installation must serve pre-8.0 clients and you encountercompatibility issues after upgrading, the simplest way to address thoseissues is to reconfigure the server to revert to the previous defaultauthentication plugin (mysql_native_password). For example, use these linesin the server option file:[mysqld]default_authentication_plugin=mysql_native_passwordHowever, the setting should be viewed as temporary, not as a long term orpermanent solution, because it causes new accounts created with the settingin effect to forego the improved authentication security.If you are using replication please take time to understand how theauthentication plugin changes may impact you.More information:https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatibility-issueshttps://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-replicationErrors: 0Warnings: 1Notices: 1No fatal errors were found that would prevent an upgrade, but some potential issues were detected. Please ensure that the reported issues are not significant before upgrading.
从输出报告可以看出,升级检查器在21个方面进行了检查,最终得出一个警告信息和一个提示。
通过以上的例子,读者可以发现,MySQL Shell提供的升级检查工具能够帮助用户检测版本兼容性,减轻升级工作负担。
感谢您关注“MySQL解决方案工程师”!
《深入浅出MGR》视频课程
戳此小程序即可直达B站
https://www.bilibili.com/medialist/play/1363850082?business=space_collection&business_id=343928&desc=0
文章推荐:
想看更多技术好文,点个“在看”吧!




