升级概述
PolarDB MySQL 5.7/RDS 5.7 向 8.0 升级过程中,经常遇到的问题主要是性能问题、语法兼容性问题,以及周边组件是否的支持,查询的性能问题一般是由于优化器升级导致执 行计划有变,此类问题需要对性能低下的语句进行针对性的性能优化,但性能问题基本不会引发业务报错以及代码的改写问题,此类问题不在本文讨论范围之内。
本文主要讨论真实的兼容性问题,此类问题需要在数据库升级过程中,对代码做出对应的更新或环境配置的更改,引发原因主要是版本升级后一些语法的变化以及特性的更新、移除。
配置兼容性
引擎和分区表兼容
有关将MyISAM 表转换为 的信息InnoDB,请参阅 第 15.6.1.5 节,“将表从 MyISAM 转换为 InnoDB”。
在 PolarDB MySQL 8.0 中 ,将导致使用没有此类支持的存储引擎的分区表的表创建语句失败并出现错误 ( ER_CHECK_NOT_IMPLEMENTED )。
PolarDB MySQL 存储引擎现在负责提供自己的分区处理程序,并且PolarDB MySQL 服务器不再提供通用分区支持。 InnoDB并且 NDB是唯一提供 PolarDB MySQL 8.0 支持的本机分区处理程序的存储引擎。必须 在升级服务器之前InnoDB更改使用任何其他存储引擎的分区表 - 将其转换为或NDB,或删除其分区 - 否则之后无法使用。如有类似分区,需要提前转换引擎后再进行升级,检查语法:
SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE ENGINE NOT IN ('innodb', 'ndbcluster') AND CREATE_OPTIONS LIKE '%partitioned%';
或者
SELECT DISTINCT NAME, SPACE, SPACE_TYPE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
WHERE NAME LIKE '%#P#%' AND SPACE_TYPE NOT LIKE 'Single';
AI 代码解读
应该更改为InnoDB引擎或删除分区
ALTER TABLE part ENGINE = INNODB;
Query OK, 0 rows affected (0.09 sec)
OR
ALTER TABLE part REMOVE PARTITIONING;
Query OK, 0 rows affected (0.06 sec)
AI 代码解读
如果使用 mysqldump从在 MySQL 5.7(或更早版本)中创建的转储文件将数据库导入PolarDB MySQL 8.0 服务器,则必须确保创建分区表的任何语句都不会同时指定不受支持的存储引擎,方法是删除对分区的任何引用,或通过将存储引擎指定为 InnoDB或允许将其设置为 InnoDB默认值。
“为升级准备安装”中给出的过程描述了如何识别在升级到 MySQL 8.0 之前必须更改的分区表。有关详细信息,请参阅“与存储引擎相关的分区限制”。
字符集&排序规则兼容
官方版本 8.0 默认字段集改为 utf8mb4,RDS/PolarDB MySQL 8.0 默认字符集为了兼容性目前默认 character_set_server 均为 utf8,可以按业务需求调整,为了改进 Unicode 支持,请考虑将使用该字符集的对象转换utf8mb3为使用该utf8mb4字符集。不推荐使用utf8mb3字符集。另外,考虑使用utf8mb4字符集引用而不是 utf8,因为当前 utf8是utf8mb3字符集的别名。有关详细信息,请参阅 utf8mb3 字符集(3 字节 UTF-8 unicode 编码)在 MySQL 文档中。
官方版本 8.0 新增了 default_collation_for_utf8mb4 参数,此参数的作用是在字符集为 utf8mb4 时,默认排序规则,默认值为 utf8mb4_0900_ai_ci,官方文档注明只是为MySQL Replication使用的内部参数,所以建议如果没有从低版本同步过程中遇到Illegal mix of collations错误前不建议修改该默认值为utf8mb4_general_ci/utf8_general_ci。
utf8mb4_unicode_ci 是基于官方Unicode的规则来做通用的排序和比较,准确度高,但比对速度稍慢。
utf8mb4_general_ci 是精简集合的排序规则,目的是提供简化的一个设计来加快速度,虽然没有去遵循Unicode的规则,但是结果在相同情况下是符合预期的。
排序规则和字符集不同,它之和排序和比较有关系,其中ai指的是口音不敏感。也就是说,排序时e,è,é,ê和ë之间没有区别, ci表示不区分大小写。也就是说,排序时p和P之间没有区别。
注意事项
-
比如在 8.0向低版本反向同步或者 dump 同步时,有可能导致脚本不支持,
-
比较容易在 DTS 低版本与高版本双向同步场景下出现,需要使用5.7默认的排序字符集,否则DTS反向同步的时候会有异常。
-
创建视图可能会报错Illegal mix of collations 原因也是由于排序规则问题,如使用 convert(a.c1 using utf8mb4) = b.c1
-
原因是使用 convert(exp using utf8mb4),不指定 collation,MySQL 按照 utf8mb4 查询,返回的 charset number 总是 255,255 对应的 collation 就是 MySQL 8.0 默认的 utf8mb4_0900_ai_ci 。
-
修改 default_collation_for_utf8mb4 ,或者是 ddl 里面指定 column,table, db 的 collation 都不会起作用。 如果一定要用 convert,可以明确带上 collation,类似这样写 (convert(a.c1 using utf8mb4) collate utf8mb4_general_ci) = b.c1
-
修改 default_collation_for_utf8mb4 默认值如 utf8mb4_unicode_ci ,会导致SYS库无法读取及其相关函数无法读取,报错“Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='”,也会导致会导致从PolarDB 8.0.1升级到PolarDB 8.0.2失败,因为该参数是8.0的新参数,所以建议不要修改该参数,如果必须使用其他值,请升级前提工单重置为默认 utf8mb4_0900_ai_ci 升级后修改回来。
参数兼容
lower_case_table_names
从 MySQL 8.0.11 开始,禁止 lower_case_table_names 使用与服务器初始化时使用的设置不同的设置来启动服务器。该限制是必要的,因为各种数据字典表字段使用的排序规则基于 lower_case_table_names 服务器初始化时定义的设置,并且使用不同的设置重新启动服务器会在标识符的排序和比较方式方面引入不一致。实例区分大小写在 8.0 版本中,无法在初始化完成后再次更改,需要在购买PolarDB MySQL 8.0实例时选定。
sql_mode
为避免PolarDB MySQL 8.0 上的启动失败,请NO_AUTO_CREATE_USER从 sql_modeMySQL 选项文件中的系统变量设置中删除任何实例。sql_mode您的系统变量设置中不得定义过时的 SQL 模式,sql_mode 会引起许多行为的不同,在版本升级时需要确认对齐。取消如下配置项:
DB2, MAXDB, MSSQL, MYSQL323, MYSQL40, ORACLE, POSTGRESQL, NO_FIELD_OPTIONS , NO_KEY_OPTIONS, NO_TABLE_OPTIONS
AI 代码解读
以上配置项大多为组合配置,需要注意是否有不一致的 mode 选项,如: sql_mode=TRADITIONAL等于配置如下项:
STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION.
AI 代码解读
在 5.7 默认配置时,sql_mode=TRADITIONAL等于配置如下项:
STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, and NO_ENGINE_SUBSTITUTION.
AI 代码解读
可以看到 5.7 多了 NO_AUTO_CREATE_USER 项,但其实 8.0 已经禁止使用 GRANT 语句隐式创建账号,5.7 虽然添加了NO_AUTO_CREATE_USER 选项,但在指定 identified by 时,同样可以使用 GRANT 创建账号。
视图/表以及关键词
InnoDB相关视图
INFORMATION_SCHEMA基于InnoDB系统表的视图被数据字典表的内部系统视图取代。受影响 InnoDB INFORMATION_SCHEMA的视图已重命名:,如果系统应用中有直接访问 InnoDB 相关视图,需要确认应用中是否已经修改。
重命名的 InnoDB 信息模式视图
旧名称 |
新名字 |
INNODB_SYS_COLUMNS |
INNODB_COLUMNS |
INNODB_SYS_DATAFILES |
INNODB_DATAFILES |
INNODB_SYS_FIELDS |
INNODB_FIELDS |
INNODB_SYS_FOREIGN |
INNODB_FOREIGN |
INNODB_SYS_FOREIGN_COLS |
INNODB_FOREIGN_COLS |
INNODB_SYS_INDEXES |
INNODB_INDEXES |
INNODB_SYS_TABLES |
INNODB_TABLES |
INNODB_SYS_TABLESPACES |
INNODB_TABLESPACES |
INNODB_SYS_TABLESTATS |
INNODB_TABLESTATS |
INNODB_SYS_VIRTUAL |
INNODB_VIRTUAL |
在 5.7 版本中不能存在 8.0 中新增的同名视图,在 5.7 实例中执行如下语句,如果有返回则需要确认如何对此类表进行处理,理论上云上 rds 无权限直 接操作 mysql 数据库,此项检查建议在自建实例上云升级时执行
SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE LOWER(TABLE_SCHEMA) = 'mysql'
and LOWER(TABLE_NAME) IN
(
'catalogs',
'character_sets',
'check_constraints',
'collations',
'column_statistics',
'column_type_elements',
'columns',
'dd_properties',
'events',
'foreign_key_column_usage',
'foreign_keys',
'index_column_usage',
'index_partitions',
'index_stats',
'indexes',
'parameter_type_elements',
'parameters',
'resource_groups',
'routines',
'schemata',
'st_spatial_reference_systems',
'table_partition_values',
'table_partitions',
'table_stats',
'tables',
'tablespace_files',
'tablespaces',
'triggers',
'view_routine_usage',
'view_table_usage'
);
Suppose
+--------------+------------+
| TABLE_SCHEMA | TABLE_NAME |
+--------------+------------+
| mysql | catalogs |
+--------------+------------+
1 row in set (0.00 sec)
AI 代码解读
因此,此类用户表应在升级前重命名或删除:
mysql>ALTER TABLE catalogs RENAME user_catalogs;
Query OK, 0 rows affected (0.05 sec)
OR
mysql> DROP TABLE catalogs;
Query OK, 0 rows affected (0.06 sec)
AI 代码解读
视图兼容
在 MySQL 8.0 之前,用户可以创建具有最多 255 个字符的显式列名的视图。为遵守列名的最大长度,MySQL 8.0 不支持显式列名超过 64 个字符的视图。目前这些视图只能通过 在 MySQL 5.7 中执行SHOW CREATE VIEW来识别。
mysql> SHOW CREATE VIEW v1;
+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| v1 | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `a123456789012345678901234567890123456789012345678901234567890123456789` | utf8 | utf8_general_ci |
+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.00 sec
AI 代码解读
应在升级前修改视图名字
mysql> ALTER VIEW v1(a12345678901234567890) AS SELECT 1;
AI 代码解读
类型兼容
枚举和集合类型兼容
表或存储过程的单个ENUM或SET列元素的长度不得超过 255 个字符或 1020 个字节。
JSON类型中INT类型数据变化
JSON里面的个别int类型被加了.0变成类似1.0或者9999.0,初步确认是MySQL 5.7和PolarDB MySQL8.0对JSON里面双精度处理方式不同导致,解决方案需要做DTS数据校验,确认前端是否对这个问题做了适配处理。
5.x 旧式类型兼容
旧式decimal s、旧式varchar、旧式TIME/DATETIME 和 TIMESTAMP类型等数据类型分别在 MySQL 5.1 、 MySQL 5.0 和 MySQL 5.6 中已过时,由于二进制升级而一直持续到 MySQL 5.7 将不被支持在 MySQL 8.0 中。这些表可以通过在升级前在 MySQL 5.7 中运行CHECK TABLE…FOR UPGRADE 或带有check-upgrade选项的 mysqlcheck 来识别。此外,使用旧式T IME/DATETIME 和 TIMESTAMP的表可以通过启用会话变量来识别,参考"How to Easily Identify Tables With Temporal Types in Old Format!"。
mysql> check table 41_decimal for upgrade;
+-----------------+-------+----------+-------------------------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------+-------+----------+-------------------------------------------------------------------------------------+
| test.41_decimal | check | error | Table upgrade required for `test`.`41_decimal`. Please dump/reload table to fix it! |
+-----------------+-------+----------+-------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> check table 55_temporal for upgrade;
+------------------+-------+----------+------------------------------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+------------------+-------+----------+------------------------------------------------------------------------------------------+
| test.55_temporal | check | error | Table upgrade required. Please do "REPAIR TABLE `55_temporal`" or dump/reload to fix it! |
+------------------+-------+----------+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
nisha@nisha-PORTEGE-Z30-A:~/workspace1/mysql-5.7/dbg-5.7/client/mysqlcheck --user=root --socket=/home/nisha/workspace1/mysql-5.7/dbg-5.7/data/mysql.sock --databases test --check-upgrade
error : Table upgrade required for `test`.`41_decimal`. Please dump/reload table to fix it!
test.55_temporal
error : Table upgrade required. Please do "REPAIR TABLE `55_temporal`" or dump/reload to fix it!
test.child OK
test.geom OK
test.jemp OK
test.jemp_myisam OK
test.opening_lines OK
test.parent OK
test.t_blackhole OK
test.t_blob OK
test.t_blob_myisam OK
test.t_compressed OK
test.t_compressed2 OK
test.t_compressed3 OK
test.t_dynamic OK
test.t_gen_stored OK
test.t_gen_stored_myisam OK
test.t_gen_stored_myisam2 OK
test.t_index OK
test.t_json OK
test.t_myisam_compressed OK
test.t_myisam_compressed2 OK
test.t_myisam_compressed3 OK
test.t_sc~!@#$%^&*( OK
test.vt2 OK
AI 代码解读
使用此类数据类型的表无法升级,应通过REPAIR TABLE 修复,并为旧式 varchar/旧式 decimal 转储/重新加载:
mysql> REPAIR TABLE 55_temporal;
+------------------+--------+----------+-------------------------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+------------------+--------+----------+-------------------------------------------------------------------------------------+
| test.55_temporal | repair | Note | TIME/TIMESTAMP/DATETIME columns of old format have been upgraded to the new format. |
| test.55_temporal | repair | status | OK |
+------------------+--------+----------+-------------------------------------------------------------------------------------+
2 rows in set (0.01 sec)
mysql>
Dump:
$./client/mysqldump --databases test --socket=5.7/data/mysql.sock --user=root>test.sql
Restore:
mysql> .\ test.sql
AI 代码解读
关键词与保留字
PolarDB MySQL 8.0 可以通过 information_schema.KEYWORDS 表查看当前版本的关键词与保留字,不得有关键字或保留字违规。PolarDB MySQL 8.0 中可能保留了一些以前未保留的关键字,有关详细信息,请参阅关键字和保留字在 MySQL 文档中。建议所有自定义内容(表名、字段名、函数 名)等等全部要规避使用。除此之外, KICKOUT 是 PolarDB MySQL 8.0 的保留关键字。因此,若您已经在 MySQL 5.7 或开源 MySQL 8.0 上使用该关键字作为对象名称(如表名、字段名、存储过程名等),在迁移到 PolarDB MySQL 8.0 前,请您先修改对象名称避免使用该关键字。否则迁移时,将会出现错误码为1064 的语法报错。
补充关键词(RDS)
有业务会使用自建序列号生成器函数 nextval、currval,这两个关键词在 RDS MySQL 8.0 中为保留字,需要改写函数名称或者直接使用 RDS 提供的 seq 功能
CREATE sequence s START WITH 1 minvalue 1 MAXVALUE 9999999 increment BY 1 CACHE 20 cycle;
SELECT nextval(s),currval(s);
AI 代码解读
SQL兼容性
GRANT授权
在 MySQL 8.0.11 中,删除了与帐户管理相关的几个已弃用的功能,例如使用 GRANT语句修改用户帐户的非特权特性。例如
GRANT REPLICATION CLIENT ON *.* TO 'odps'@'%'; You are not allowed to create a user with GRANT 需要改为两步建
create user;
grant privielges;
AI 代码解读
不支持 GROUP BY ASC/DESC 写法
从 MySQL 8.0.13 开始,已删除不推荐使用的子句ASC或 DESC限定符GROUP BY以前依赖GROUP BY排序的查询可能会产生与以前的 MySQL 版本不同的结果。要生成给定的排序顺序,请提供一个ORDER BY子句。
select id,count(*) from sbtest.sbtest1 where id < 10 group by id desc
AI 代码解读
需要改写为
select id,count(*) from sbtest.sbtest1 where id < 10 group by id order by id
AI 代码解读
外键约束定义
在 MySQL 5.7 中,定义FOREIGN KEY定义的InnoDB 不带CONSTRAINT 的关键字或者指定外键约束名称不得超过 64 个字符。在 MySQL 8.0 之前的版本中,当用户未明确指定时,InnoDB 通过在表名后附加 '_ibfk_X' 来自动生成外键约束名称,其中 X 是一个数字。如果表名是多字节 64 个字符,例如下面示例中使用的西里尔表名 'имя_базы_в_кодировке_утф8_длиной_больше_чем_45имя_азы_в_кодировк',则自动生成的外键约束名称超过 64 个字符。应通过删除约束并通过确保外键约束名称不超过 64 个字符来添加具有显式约束名称的约束来更改这些表。
mysql> ALTER TABLE `имя_базы_в_кодировке_утф8_длиной_больше_чем_45имя_азы_в_кодировк` DROP FOREIGN KEY `имя_базы_в_кодировке_утф8_длиной_больше_чем_45имя_азы_в_кодировк_ibfk_1`;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> ALTER TABLE `имя_базы_в_кодировке_утф8_длиной_больше_чем_45имя_азы_в_кодировк` ADD CONSTRAINT FOREIGN KEY FK1 (fld2) REFERENCES t1(fld1);
Query OK, 0 rows affected (0.13 sec)
Records: 0 Duplicates: 0 Warnings: 0
AI 代码解读
空间函数
在 MySQL 5.7 中,不推荐使用多个名称下可用的几个空间函数。示例PointFromText:
mysql> CREATE TABLE t_gcol_dep (fid INTEGER NOT NULL PRIMARY KEY, g POINT GENERATED ALWAYS AS (PointFromText(POINT(10, 10))));
Query OK, 0 rows affected, 1 warning (0.07 sec)
mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | 'POINTFROMTEXT' is deprecated and will be removed in a future release. Please use ST_POINTFROMTEXT instead |
+---------+------+------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
AI 代码解读
由于空间函数名称空间更改,这些空间函数在 MySQL 8.0 中被删除。此更改有助于命名约定保持一致,即函数以“ST_”开头(如果它执行精确操作),或者以“MBR”开头(如果它执行基于最小边界矩形的操作)。使用此类函数生成的列应在升级前更改。可以在以下文档中找到已删除空间函数的列表。 必须更改生成的列以使用相应的“ST_”或“MBR”函数。
mysql> ALTER TABLE t_gcol_dep MODIFY g POINT GENERATED ALWAYS AS (ST_POINTFROMTEXT(POINT(10, 10)));
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
AI 代码解读
触发器兼容
MySQL 5.0.17 之前的 CREATE TRIGGER 不支持 definer 属性。此类具有缺失/空定义器属性或无效创建上下文(即 character_set_client、collation_collection、数据库排序规则属性)的触发器定义 一直存在到 MySQL 5.7 无法升级。这些触发器可以通过在 MySQL 5.7 中运行带有检查升级选项的mysqlcheck或CHECK TABLE来识别。
$./client/mysqlcheck --user=root --socket=5.7/data/mysql.sock --databases triggers --check-upgrade
triggers.t1
Warning : No definer attribute for trigger 'triggers'.'trg_t1_before_insert'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
Warning : No definer attribute for trigger 'triggers'.'t1_bi'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
Warning : No definer attribute for trigger 'triggers'.'trg_t1_after_insert_1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
Warning : No definer attribute for trigger 'triggers'.'trg_t1_after_insert'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
Warning : No definer attribute for trigger 'triggers'.'trg_t1_after_insert_3'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
Warning : No definer attribute for trigger 'triggers'.'trg_t1_before_update_3'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
Warning : No definer attribute for trigger 'triggers'.'trg_t1_before_update'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
Warning : No definer attribute for trigger 'triggers'.'trg_t1_after_update'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
Warning : No definer attribute for trigger 'triggers'.'trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
status : OK
triggers.t2 OK
mysql> check table t1;
+-------------+-------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-------------+-------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'trg_t1_before_insert'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'t1_bi'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'trg_t1_after_insert_1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'trg_t1_after_insert'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'trg_t1_after_insert_3'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'trg_t1_before_update_3'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'trg_t1_before_update'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'trg_t1_after_update'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | Warning | No definer attribute for trigger 'triggers'.'trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. |
| triggers.t1 | check | status | OK |
+-------------+-------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
10 rows in set (0.01 sec)
mysql> select definer, trigger_name from INFORMATION_SCHEMA.TRIGGERS where definer='';
+---------+------------------------+
| definer | trigger_name |
+---------+------------------------+
| | trg_t1_before_insert |
| | t1_bi |
| | trg_t1_after_insert_1 |
| | trg_t1_after_insert |
| | trg_t1_after_insert_3 |
| | trg_t1_before_update_3 |
| | trg_t1_before_update |
| | trg_t1_after_update |
| | trg1 |
+---------+------------------------+
9 rows in set (0.02 sec)
mysql>
AI 代码解读
应转储/重新加载此类触发器以解决问题:
Dump:
$./client/mysqldump --databases triggers --socket=5.7/data/mysql.sock --user=root>triggers.sql
Restore:
mysql> .\ triggers.sql
AI 代码解读
并行查询导致的排序问题
PolarDB MySQL 8.0开始支持并行查询能力,并行扫描由于随机访问数据导致MySQL默认串行扫描的顺序每次会随机变化,尤其涉及到分页的SQL,需要要生成给定的排序顺序,请提供一个ORDER BY子句保证顺序。
其他
客户端兼容
对于 java 应用来说,MySQL Connector/J 升级到 5.1.46 以上版本 到 8.0.8 能够连接到 MySQL 8.0 服务器,但使用 caching_sha2_password. (连接帐户需要连接器/J 8.0.9 或更高版本 caching_sha2_password。)。
dataworks由于未在数据源中设置utf8可能出错,建议修改数据库名,并和RDS的设置一致。在PolarDB MySQL的连接串增加:characterEncoding=utf8&com.mysql.jdbc.faultInjection.serverCharsetIndex=
Unknown system variable 'tx_read_only'
8.0 中已经删除 tx_read_only 环境变更,需要使用 transaction_read_only 代替
select @@tx_read_only
AI 代码解读
需要改为
select @@transaction_read_only
AI 代码解读
升级检查器
官方目前提供了8.0升级检查器,目前PolarDB MySQL未支持,自建库升级前请参考检查器。
参考文档