×
Community Blog Best Practices for Upgrading PolarDB for MySQL 5.6/MySQL 5.6 to PolarDB for MySQL 8.0

Best Practices for Upgrading PolarDB for MySQL 5.6/MySQL 5.6 to PolarDB for MySQL 8.0

This article describes the common issues encountered during the upgrade from PolarDB for MySQL 5.6/MySQL 5.6 to PolarDB for MySQL 8.0.

By Daoke

Upgrade Overview

During the upgrade from PolarDB for MySQL 5.6/MySQL 5.6 to PolarDB for MySQL 8.0, common issues arise with performance, syntax compatibility, and peripheral component support. Performance problems in queries are usually caused by changes in the execution plan due to optimizer upgrades. However, such issues can be resolved through targeted performance optimization and do not require rewriting code or cause business errors. Therefore, this article will not discuss such issues.

This article focuses on actual compatibility problems that necessitate code updates or changes in the environment configuration during the database upgrade process. These problems arise due to syntax changes, feature updates, and removals in newer versions. To help users identify potential issues during the upgrade, a pre-inspection checklist is provided. If any of the following problems are encountered, users can refer to the Version Upgrade Details section for operation and inspection.

  • Ensure that obsolete data types, functions, and features are not used. For more information, see the official documentation Features Removed in MySQL 8.0.
  • Ensure that triggers have no missing or empty definer or invalid content.
  • Ensure that there are only partition tables of the InnoDB engine.
  • Ensure that the keywords do not conflict with the reserved keywords. For more information, see the official documentation Keywords and Reserved Words.
  • Ensure that there is no conflict with the system database of MySQL 5.6 and with the new dictionary table name beginning with INNODB_ in MySQL 8.0.
  • Ensure that there is no dependency on the GLOBAL | LOCAL]_[VARIABLES | STATUS] table under INFORMATION_SCHEMA.
  • Ensure that no obsolete variable settings are used in sql_mode.
  • Ensure that the length of a single ENUM or SET column element in a table or stored procedure does not exceed 255 characters or 1020 bytes.
  • Ensure that the table partition is not in the shared InnoDB tablespaces.
  • Ensure that the GROUP BY clause in the SQL statement does not contain ASC or DESC.
  • Ensure that the foreign key constraint name does not exceed 64 characters.
  • Check whether Derived Tables exist in the SQL queries and require subsequent attention to the SQL performance.
  • If you want to enhance the Unicode support, it is recommended to convert the tables, views, and functions that use the utf8mb3 character set (obsolete) to those use the utf8mb4 character set. In addition, it is recommended that use utf8mb4 to replace utf8, because utf8 is an alias for the utf8mb3 character set. For more information, see The utf8mb3 Character Set (3-byte UTF-8 unicode encoding).

If the preceding problems do not exist, you can skip the following section and upgrade. For more information, see Major Version One-touch Upgrade of PolarDB for MySQL Engine. Note: Be sure to back up before upgrading to avoid other problems that may occur during the upgrade. In addition, the DAS team of DAMO Academy has also launched the intelligent stress testing capability to facilitate customers to perform stress testing on the flow playback of newly upgraded instances.

Version Upgrade Details

Configuration Compatibility

Engine and Partition Table Compatibility

For information about converting MyISAM tables to InnoDB, see Converting Tables from MyISAM to InnoDB. In PolarDB for MySQL 8.0, creating a partition of MyISAM type will cause a storage engine partition table that does not support this type to fail to create statements and report an error (ER_CHECK_NOT_IMPLEMENTED).

The PolarDB for MySQLs storage engines now provide their own partition handlers, and PolarDB for MySQL servers no longer provide general-purpose engine partition support. InnoDB is the only storage engine that provides native partition handlers supported by PolarDB for MySQL 8.0. Before upgrading the server, you need to convert the partition tables of non-InnoDB storage engine to the partition tables of InnoDB storage engine, or delete the partition tables and convert them to regular tables. Otherwise, it cannot be used later. If there are similar partitions, you need to convert the engine in advance before upgrading. Check the engine syntax as follows:

<mysql> ALTER TABLE part ENGINE = INNODB;
Query OK, 0 rows affected (0.09 sec)
 
OR
 
<mysql> ALTER TABLE part REMOVE PARTITIONING;
Query OK, 0 rows affected (0.06 sec)

If you use a MySQLdump to import a database into a PolarDB for MySQL 8.0 server from a dump file created in MySQL 5.6 (or earlier), you must ensure that any statement that creates a partition table does not specify an unsupported storage engine. In doing so, you need to remove any references to the partition, specify the storage engine as InnoDB, or allow the engine to be set as the default value of InnoDB. The procedures in "Prepare Installation for Upgrade" describe how to identify partition tables that must be changed before upgrading to MySQL 8.0. For more information, see Storage Engine-Related Partition Restrictions.

Character Set & Collation Compatibility

In MySQL 8.0, the default field set is changed to utf8mb4. The character_set_server values of MySQL 8.0 and PolarDB for MySQL 8.0 are utf8 by default for compatibility. You can adjust it based on your business requirements. If you want to improve the Unicode support, you are recommended to convert the utf8mb3 character set to the utf8mb4 character set. The utf8mb3 character set is not recommended. In addition, it is recommended that use the utf8mb4 character set reference to replace utf8, because utf8 is an alias for the utf8mb3 character set. For more information, see utf8mb3 Character Set (3-byte UTF-8 unicode encoding) in the MySQL documentation.

MySQL 8.0 has added the default_collation_for_utf8mb4 parameter, which is used to sort according to the default collation when the character set is utf8mb4. The default value of the parameter is utf8mb4_0900_ai_ci. The official documentation indicates that it is only an internal parameter used by MySQL Replication. Therefore, we recommend that you do not change the default value to utf8mb4_general_ci/utf8_general_generic_ci if you do not encounter the Illegal mix of collations errors during the process of synchronizing from a lower version to a higher version.

utf8mb4_unicode_ci is used for general sorting and comparison based on official Unicode rules. The accuracy is high, but the comparison speed is slightly slower.

utf8mb4_general_ci is a collation that simplifies sets. Its purpose is to provide a simplified design to speed up. Although it does not follow the Unicode rules, the results are in line with expectations in the same situation.

Sorting rules are different from character sets. They are related to sorting and comparison, where ai refers to accent insensitivity. In other words, there is no difference between e,è,é,ê and ë when sorting, and ci means case insensitivity. That is, there is no difference between p and P during sorting.

Usage note

  • For example, the script may not be supported when reverse synchronization or dump synchronization is performed from MySQL 8.0 to earlier versions.
  • This is easy to occur in two-way synchronization between earlier and later versions of DTS. You must use the default sorting character sets of PolarDB for MySQL 5.6/MySQL 5.6. Otherwise, exceptions may occur when DTS performs reverse synchronization.
  • The Illegal mix of collations errors may be reported due to collation problems when you create a view, such as using convert(a.c1 using utf8mb4) = b.c1.
  • The reason is that if you use convert(exp using utf8mb4) and do not specify collation, MySQL will query according to utf8mb4. At this time, the returned charset number is always 255, and the collation corresponding to 255 is the default utf8mb4_0900_ai_ci of MySQL 8.0.
  • Modifying the default_collation_for_utf8mb4, or specifying the collations of column, table, and db in DDL will not work. If you need to use the convert function, you can add collation to the statement, such as (convert (a.c1 using utf8mb4) collate utf8mb4_general_ci) = b.c1.
  • If you change the default value of default_collation_for_utf8mb4, such as changing it to utf8mb4_unicode_ci, the SYS library cannot be read, and its related functions cannot be read. In this case, the error "Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='" is reported. In addition, it will cause the upgrade from PolarDB 8.0.1 to PolarDB 8.0.2 to fail. This parameter is newly added in PolarDB 8.0, so it is recommended not to modify this parameter. If you must use other values, apply to reset the default value of the parameter to utf8mb4_0900_ai_ci before upgrading. After the upgrade is finished, modify it to the original value.

Parameter Compatibility

lower_case_table_names

Starting with MySQL 8.0.11, lower_case_table_names are prohibited from starting the server with settings different from those used when the server was initialized. This restriction is necessary because the collation used by various data dictionaries and table fields is based on the settings defined when the lower_case_table_names server is initialized. When the server is restarted with different settings, inconsistencies in how identifiers are sorted and compared will be introduced. In PolarDB for MySQL 8.0, the instance case sensitivity cannot be changed again after initialization. You must select whether to choose case sensitivity when you purchase a PolarDB for MySQL 8.0 instance.

sql_mode

To avoid startup failures of PolarDB for MySQL 8.0, remove all instances from the system variable sql_mode setting in the MySQL options file via NO_AUTO_CREATE_USER. Obsolete SQL modes must not be defined in your system variable settings. Otherwise, sql_mode will cause many different behaviors. Alignment must be confirmed during version upgrade. Cancel the following configuration items:

DB2, MAXDB, MSSQL, MYSQL323, MYSQL40, ORACLE, POSTGRESQL, NO_FIELD_OPTIONS , NO_KEY_OPTIONS, NO_TABLE_OPTIONS

Most of the above configuration items are combined configurations. Pay attention to whether there are inconsistent mode options. For example, sql_mode=TRADITIONAL equals configuring the following items:

STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION.

In the default configurations of PolarDB for MySQL 5.6/MySQL 5.6, the sql_mode=TRADITIONAL equals configuring the following items:

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.

Compared with the above configuration items, we can see that the NO_AUTO_CREATE_USER option is added in PolarDB for MySQL 5.6/MySQL 5.6. However, MySQL 8.0 has prohibited the implicit creation of accounts using GRANT statements. Although the NO_AUTO_CREATE_USER option is added in PolarDB for MySQL 5.6/MySQL 5.6, GRANT can also be used to create accounts when the identified by is specified.

If you find that enabling ONLY_FULL_GROUP_BY causes queries on the existing application to be rejected, you can use the following methods to resume the operation:

  • If you can modify the problematic query, you can make non-deterministic and non-aggregated columns depend on the GROUP BY list functionally, or you can use ANY_VALUE().
  • If you cannot modify the problematic query (for example, it is generated by a third-party application), set the system variable sql_mode when the server starts up to not enable ONLY_FULL_GROUP_BY.

For example, this situation happens when the description is not part of the GROUP BY list, and no aggregation function (such as MIN or MAX) is applied.

Previous behavior:

SELECT id, invoice_id, description FROM invoice_line_items GROUP BY invoice_id;  
+----+------------+-------------+  
| id | invoice_id | description |  
+----+------------+-------------+  
| 1 | 1 | New socks             |  
| 3 | 2 | Shoes                 |  
| 5 | 3 | Tie                   |  
+----+------------+-------------+  
3 rows in set (0.00 sec)

PolarDB for MySQL 8.0:

SELECT id, invoice_id, description FROM invoice_line_items GROUP BY invoice_id;
ERROR 1055 (42000): Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'invoice_line_items.description' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Tables With Information About System and State Variables in INFORMATION_SCHEMA

Tables with information about systems and state variables in the INFORMATION_SCHEMA of MySQL 5.6/PolarDB for MySQL 5.6 are discarded in PolarDB for MySQL 8.0.

INFORMATION_SCHEMA.GLOBAL_VARIABLES
INFORMATION_SCHEMA.SESSION_VARIABLES

INFORMATION_SCHEMA.GLOBAL_STATUS
INFORMATION_SCHEMA.SESSION_STATUS

The above obsolete tables are migrated to the PERFORMANCE_SCHEMA ofPolarDB for MySQL 8.0/MySQL 8.0.

performance_schema.global_variables
performance_schema.session_variables
performance_schema.variables_by_thread

performance_schema.global_status
performance_schema.session_status
performance_schema.status_by_thread
performance_schema.status_by_account
performance_schema.status_by_host
performance_schema.status_by_user

If you want to use this view, it is recommended to use the SHOW command instead of using the corresponding view directly.

SHOW VARIABLES
SHOW STATUS

View/Table and Keyword

InnoDB-related Views

INFORMATION_SCHEMA views based on InnoDB system tables are replaced by internal system views of data dictionary tables. The affected InnoDB INFORMATION_SCHEMA view has been renamed. When directly accessing InnoDB-related views in the system application, it is necessary to confirm whether they have been modified in the application.

Renamed InnoDB Information Mode View

Old Name New name
INNODB_SYS_COLUMNS INNODB_COLUMNS/td>
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

A view with the same name newly added in PolarDB for MySQL 8.0 cannot exist in MySQL 5.6/PolarDB for MySQL 5.6. Run the following statements in the instances of MySQL 5.6/PolarDB for MySQL 5.6. If there is a return, you need to confirm how to handle such tables. We recommend that you execute this check on the user-created instances during the cloud upgrade.

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)

Therefore, such user tables should be renamed or deleted before the upgrade:

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)

View Compatibility

Before MySQL 8.0, you can create views with explicit column names of up to 255 characters. In order not to exceed the maximum length of column names, MySQL 8.0 does not support views with explicit column names longer than 64 characters. At present, these views can only be identified by executing SHOW CREATE VIEW in MySQL 5.6.

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

System Table Compatibility

The Password column mysql.user of the mysql.user system table is deleted after MySQL 5.7.6 and MySQL 8.0. All credentials are stored in the authentication_string column, including those previously stored in the Password column.

INNODB Table Compatibility

DYNAMIC replaces COMPACT and becomes the implicit default row format of InnoDB tables. A new configuration option innodb_default_row_format specifies the default InnoDB row format. The values (default) of DYNAMIC are allowed to include COMPACT, and REDUNDANT. After you upgrade to PolarDB for MySQL 8.0, any new tables that you create use the defined row format, innodb_default_row_format, unless you explicitly define the row format ( ROW_FORMAT). For the existing table ROW_FORMAT=DEFAULT that the ROW_FORMAT option is not explicitly defined or used, any reconstruction of the table will silently change the row format of the table to the defined format innodb_default_row_format. Otherwise, the existing table retains its current row format. For more information, see Define Table Row Formats.

Type Compatibility

Enumeration and Set Type Compatibility

The length of a single ENUM or SET column element of a table or stored procedure must not exceed 255 characters or 1020 bytes.

YEAR Type

The YEAR(2) type is obsolete and needs to be replaced with YEAR(4).

Type Data Insertion Compatibility

  • Inserting a negative value into an unsigned column will report an error.

Create a table with unsigned columns:

CREATE TABLE test (id int unsigned);

Insert a negative value. The result in PolarDB for MySQL 5.6 is as follows:

INSERT INTO test VALUES (-1);
Query OK, 1 row affected, 1 warning (0.01 sec)

The result in PolarDB for MySQL 8.0 is as follows:

INSERT INTO test VALUES (-1);  
ERROR 1264 (22003): Out of range value for column 'a' at row 1
  • Dividing by zero will report an error.

Create a test table.

CREATE TABLE test2 (id int unsigned);

Divide by zero. The result in PolarDB for MySQL 5.6 is as follows:

INSERT INTO test2 VALUES (0/0);  
Query OK, 1 row affected (0.01 sec)

The result in PolarDB for MySQL 8.0 is as follows:

INSERT INTO test2 VALUES (0/0);  
ERROR 1365 (22012): Division by 0
  • An error will be reported when overlength characters are inserted.

Inserting a 20-character string into a 10-character column will report an error. Create a table that contains a 10-character column:

CREATE TABLE test3 (a varchar(10));

Try to insert a longer string. The result in PolarDB for MySQL 5.6 is as follows:

INSERT INTO test3 VALUES ('abcdefghijklmnopqrstuvwxyz'); 
Query OK, 1 row affected, 1 warning (0.00 sec)

The result in PolarDB for MySQL 8.0 is as follows:

INSERT INTO test3 VALUES ('abcdefghijklmnopqrstuvwxyz');  
ERROR 1406 (22001): Data too long for column 'a' at row 1
  • An error will be reported when a non-standard zero date is inserted into the datetime column.

Create a table that contains a datetime column:

CREATE TABLE test3 (a datetime);

Insert 0000-00-00 00:00:00. The result in PolarDB for MySQL 5.6 is as follows:

INSERT INTO test3 VALUES ('0000-00-00 00:00:00');  
Query OK, 1 row affected, 1 warning (0.00 sec)

The result in PolarDB for MySQL 8.0 is as follows:

INSERT INTO test3 VALUES ('0000-00-00 00:00:00');  
ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1

5.x Legacy Type Compatibility

Data types such as legacy decimal, legacy varchar, and legacy TIME/DATETIME and TIMESTAMP are obsolete in MySQL 5.1, MySQL 5.0, and MySQL 5.6, respectively. This is because binary upgrades will not be supported in MySQL 8.0 as they are only available in MySQL 5.6. These tables can be identified by running CHECK TABLE…FOR UPGRADE or mysqlcheck with the check-upgrade option in MySQL 5.6 before the upgrade. In addition, tables that use the legacy TIME/DATETIME and TIMESTAMP can be identified by enabling session variables. For more information, see 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.6/dbg-5.6/client/mysqlcheck --user=root --socket=/home/nisha/workspace1/mysql-5.6/dbg-5.6/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

Tables that use such data types cannot be upgraded and should be fixed via REPAIR TABLE and dumped or reloaded for legacy varchar or legacy 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.6/data/mysql.sock --user=root>test.sql
 
Restore:
mysql> .\ test.sql 

Keyword and Reserved Words

PolarDB for MySQL 8.0 can view the keywords and reserved words of the current version through the information_schema. KEYWORDS table to ensure that there are no illegal keywords and reserved words. Some previously unreserved keywords may be reserved in the PolarDB for MySQL 8.0. For more information, see Keywords and Reserved Words in the MySQL documentation. We recommend that you avoid using all custom content (table names, field names, and function names). KICKOUT is a reserved keyword of PolarDB for MySQL 8.0. Therefore, if you have used this keyword as an object name (such as a table name, a field name, or a stored procedure name) in MySQL 5.6 or open source MySQL 8.0, you must modify the object name to avoid using this keyword before you upgrade to PolarDB for MySQL 8.0. Otherwise, the error code 1064 that indicates a syntax error is returned.

Supplementary keywords (RDS)

Some businesses will use the self-built serial number generator functions nextval and currval. These two keywords are reserved words in RDS for MySQL 8.0. You need to change the function names or directly use the seq function provided by RDS.

CREATE sequence s START WITH 1 minvalue 1 MAXVALUE 9999999 increment BY 1 CACHE 20 cycle;
SELECT nextval(s),currval(s);

SQL Compatibility

GRANT Authorization

In MySQL 8.0.11, several obsolete features related to account management, such as using GRANT statements to modify non-privileged features of user accounts, have been removed. Example:

GRANT REPLICATION CLIENT ON *.* TO 'odps'@'%'; You are not allowed to create a user with GRANT needs to be created by two steps
create user;
grant privielges;

GROUP BY ASC and DESC Are not Supported.

Starting with MySQL 8.0.13, the obsolete clause ASC or the DESC qualifier GROUP BY has been removed. The queries that relied on GROUP BY sorting might produce different results compared with those of previous MySQL versions. To generate a given sort order, you need to provide an ORDER BY clause.

select id,count(*) from sbtest.sbtest1 where id < 10 group by id desc

The SQL statement needs to be rewritten as:

select id,count(*) from sbtest.sbtest1 where id < 10 group by id order by id

#### Definition of Foreign Key Constraint
In MySQL 5.6, InnoDB that defines FOREIGN KEY must not have the keyword CONSTRAINT and specify that the foreign key constraint name must not exceed 64 characters. In versions earlier than MySQL 8.0, when you did not explicitly specify the foreign key constraint name, InnoDB would automatically generate the foreign key constraint name by appending '_ibfk_X' to the table name, where X is a number. If the table name is multi-byte 64 characters, such as the Cyrillic table name 'имя_базы_в_кодировке_утф8_длиной_больше_чем_45имя_азы_в_кодировк 'used in the following example, the automatically generated foreign key constraint name exceeds 64 characters. You should change these tables by removing the constraint and adding a constraint with an explicit constraint name by ensuring that the foreign key constraint name does not exceed 64 characters.

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

Trigger Compatibility

CREATE TRIGGER earlier than MySQL 5.0.17 does not support the definer attribute. Such trigger definitions with missing or empty definer attributes or invalid creation contexts (i.e. character_set_client, collation_collection, database collation attributes) persist, causing MySQL 5.6 to fail to upgrade. These triggers can be identified by running mysqlcheck or CHECK TABLE with the option to check for upgrades in MySQL 5.6.

$./client/mysqlcheck --user=root --socket=5.6/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>

Such triggers should be dumped or reloaded to resolve the following problems:

Dump:
$./client/mysqldump --databases triggers --socket=5.6/data/mysql.sock --user=root>triggers.sql
 
Restore:
mysql> .\ triggers.sql

Sorting Problems Caused by Parallel Queries

PolarDB for MySQL 8.0 supports parallel queries. Parallel scanning causes MySQL's default serial scanning order to change randomly each time due to random data access, especially when paged SQL is involved. If you need to create a given sorting order, provide an ORDER BY clause to ensure the order.

Subquery Problem

ORDER BY in a subquery no longer works. Example:

SELECT *
FROM
 (
  SELECT * FROM `information_schema`. TABLES
  ORDER BY table_name DESC
 ) AS sg
GROUP BY table_name

The ORDER BY of the inner layer will be ignored by the optimizers of PolarDB for MySQL 5.7 and 8.0. You need to modify the statement. The simplest method is to add a limit to make the sorting take effect. For example:

SELECT *
FROM
 (
  SELECT * FROM `information_schema`. TABLES
  ORDER BY table_name DESC limit 10000 # 需要足够大的行数
 ) AS sg
GROUP BY table_name

Derived Table Problem

The optimizer now treats derived tables and views in clauses in a consistent manner. It uses FROM to better avoid unnecessary materialization and allows the use of pushdown conditions that produce more efficient execution plans. However, in PolarDB for MySQL 8.0 and statements such as modifying a table, if DELETE uses the merge strategy for a derived table previously implemented by UPDATE, the ER_UPDATE_TABLE_USED error will occur:

mysql> DELETE FROM t1
    -> WHERE id IN (SELECT id
    ->              FROM (SELECT t1.id
    ->                    FROM t1 INNER JOIN t2 USING (id)
    ->                    WHERE t2.status = 0) AS t);
ERROR 1093 (HY000): You can't specify target table 't1'
for update in FROM clause

Merging a derived table into an outer query block will cause an error when you select and modify table statements from the table. (Materialization does not cause problems because it actually converts the derived table to a separate table.) The workaround to avoid this error is to disable the derived_merge flag, optimizer_switch, of the system variable before executing the statement.

SET optimizer_switch = 'derived_merge=off';

This derived_merge flag controls whether the optimizer attempts to merge subqueries and views in the FROM clause into the outer query block. Assume that there are no other rules preventing merging. By default, the merging is enabled when the flag is on. Set the flag to off to prevent merging and avoid the error just described. For more information, see Section 8.2.2.4: Using Merge or Implementation to Optimize Derived Tables and Viewing References.

  • In a UNION statement, to apply ORDER BY or LIMIT to a personal SELECT, put the SELECT clause in parentheses:
(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);

Previous versions of MySQL may allow such statements without parentheses. However, in PolarDB for MySQL 8.0, parentheses are mandatory.

GET_LOCK Function Compatibility

The GET_LOCK() function was reimplemented in MySQL 5.7.5 using the metadata locking (MDL) subsystem, and its function has been extended:

  • In previous versions, GET_LOCK() only allowed one named lock to be acquired at a time, and all existing locks were released when GET_LOCK() was called a second time. GET_LOCK() now allows multiple named locks to be acquired simultaneously and does not release existing locks.
  • Applications that rely on the behavior of GET_LOCK() to release all previous locks must be modified for the new behavior.
  • The ability to acquire multiple locks may lead to deadlocks between clients. The MDL subsystem detects deadlocks and ER_USER_LOCK_DEADLOCK returns an error when a deadlock is detected.
  • The MDL subsystem specifies that the lock names are no longer than 64 characters, so this limit also applies to named locks. In previous versions, there is no such limit.
  • The locks acquired by GET_LOCK() now appear in the Performance Schema metadata_locks table. The OBJECT_TYPE column indicates the USER LEVEL LOCK, and the OBJECT_NAME column indicates the lock name.
  • MySQL 8.0 allows RELEASE_ALL_LOCKS() to release all acquired named locks at once.

For more information, see Section 12.15: Locking Functions.

Others

Client Compatibility

For Java applications, MySQL Connector/J is recommended to be upgraded to version 8.0.8 and above. Version 8.0.8 and above can connect to MySQL 8.0 server, but caching_sha2_password is used. (Connector/J 8.0.9 or higher caching_sha2_password is required for connection accounts.).

If dataworks is not set to utf8 in the data source, an error may occur. It is recommended to change the database name to be consistent with RDS. Add the following connection string to PolarDB for MySQL: characterEncoding=utf8&com.mysql.jdbc.faultInjection.serverCharsetIndex=

Unknown system variable 'tx_read_only'

The tx_read_only Environment Changes Have Been Deleted in PolarDB for MySQL 8.0 and Need to Be Replaced by transaction_read_only.

select @@tx_read_only

Need to be changed to:

select @@transaction_read_only

Upgrade Checker

The official website provides the version 8.0 upgrade checker, which is not supported by PolarDB for MySQL. For more information about upgrading self-built databases, see Checker.

References

0 1 0
Share on

Morningking

7 posts | 0 followers

You may also like

Comments

Morningking

7 posts | 0 followers

Related Products