Mysql:8.0.19:Upgrading Mysql:升级
- 2.11.1 Before You Begin
- 2.11.2 Upgrade Paths
- 2.11.3 What the MySQL Upgrade Process Upgrades
- 2.11.4 Changes in MySQL 8.0
- 2.11.5 Preparing Your Installation for Upgrade
- 2.11.6 Upgrading MySQL Binary or Package-based Installations on Unix/Linux
- 2.11.7 Upgrading MySQL with the MySQL Yum Repository
- 2.11.8 Upgrading MySQL with the MySQL APT Repository
- 2.11.9 Upgrading MySQL with the MySQL SLES Repository
- 2.11.10 Upgrading MySQL on Windows
- 2.11.11 Upgrading a Docker Installation of MySQL
- 2.11.12 Upgrade Troubleshooting
- 2.11.13 Rebuilding or Repairing Tables or Indexes
- 2.11.14 Copying MySQL Databases to Another Machine
This section describes the steps to upgrade a MySQL installation.
Upgrading is a common procedure, as you pick up bug fixes within the same MySQL release series or significant features between major MySQL releases. You perform this procedure first on some test systems to make sure everything works smoothly, and then on the production systems.
In the following discussion, MySQL commands that must be run using a MySQL account with administrative privileges include -u on the command line to specify the MySQL rootroot user. Commands that require a password for root also include a -p option. Because -p is followed by no option value, such commands prompt for the password. Type the password when prompted and press Enter.
SQL statements can be executed using the mysql command-line client (connect as root to ensure that you have the necessary privileges).
Review the information in this section before upgrading. Perform any recommended actions.
-
Understand what may occur during an upgrade. See Section 2.11.3, “What the MySQL Upgrade Process Upgrades”.
-
Protect your data by creating a backup. The backup should include the
mysqlsystem database, which contains the MySQL data dictionary tables and system tables. See Section 7.2, “Database Backup Methods”.ImportantDowngrade from MySQL 8.0 to MySQL 5.7, or from a MySQL 8.0 release to a previous MySQL 8.0 release, is not supported. The only supported alternative is to restore a backup taken before upgrading. It is therefore imperative that you backup your data before starting the upgrade process.
-
Review Section 2.11.2, “Upgrade Paths” to ensure that your intended upgrade path is supported.
-
Review Section 2.11.4, “Changes in MySQL 8.0” for changes that you should be aware of before upgrading. Some changes may require action.
-
Review Section 1.4, “What Is New in MySQL 8.0” for deprecated and removed features. An upgrade may require changes with respect to those features if you use any of them.
-
Review Section 1.5, “Server and Status Variables and Options Added, Deprecated, or Removed in MySQL 8.0”. If you use deprecated or removed variables, an upgrade may require configuration changes.
-
Review the Release Notes for information about fixes, changes, and new features.
-
If you use replication, review Section 17.5.3, “Upgrading a Replication Setup”.
-
Upgrade procedures vary by platform and how the initial installation was performed. Use the procedure that applies to your current MySQL installation:
-
For binary and package-based installations on non-Windows platforms, refer to Section 2.11.6, “Upgrading MySQL Binary or Package-based Installations on Unix/Linux”.
NoteFor supported Linux distributions, the preferred method for upgrading package-based installations is to use the MySQL software repositories (MySQL Yum Repository, MySQL APT Repository, and MySQL SLES Repository).
-
For installations on an Enterprise Linux platform or Fedora using the MySQL Yum Repository, refer to Section 2.11.7, “Upgrading MySQL with the MySQL Yum Repository”.
-
For installations on Ubuntu using the MySQL APT repository, refer to Section 2.11.8, “Upgrading MySQL with the MySQL APT Repository”.
-
For installations on SLES using the MySQL SLES repository, refer to Section 2.11.9, “Upgrading MySQL with the MySQL SLES Repository”.
-
For installations performed using Docker, refer to Section 2.11.11, “Upgrading a Docker Installation of MySQL”.
-
For installations on Windows, refer to Section 2.11.10, “Upgrading MySQL on Windows”.
-
-
If your MySQL installation contains a large amount of data that might take a long time to convert after an in-place upgrade, it may be useful to create a test instance for assessing the conversions that are required and the work involved to perform them. To create a test instance, make a copy of your MySQL instance that contains the
mysqldatabase and other databases without the data. Run the upgrade procedure on the test instance to assess the work involved to perform the actual data conversion. -
Rebuilding and reinstalling MySQL language interfaces is recommended when you install or upgrade to a new release of MySQL. This applies to MySQL interfaces such as PHP
mysqlextensions and the PerlDBD::mysqlmodule.
-
Upgrade from MySQL 5.7 to 8.0 is supported. However, upgrade is only supported between General Availability (GA) releases. For MySQL 8.0, it is required that you upgrade from a MySQL 5.7 GA release (5.7.9 or higher). Upgrades from non-GA releases of MySQL 5.7 are not supported.
-
Upgrading to the latest release is recommended before upgrading to the next version. For example, upgrade to the latest MySQL 5.7 release before upgrading to MySQL 8.0.
-
Upgrade that skips versions is not supported. For example, upgrading directly from MySQL 5.6 to 8.0 is not supported.
-
Once a release series reaches General Availability (GA) status, upgrade within the release series (from one GA version to another GA version) is supported. For example, upgrading from MySQL 8.0.
xto 8.0.yis supported. (Upgrade involving development-status non-GA releases is not supported.) Skipping a release is also supported. For example, upgrading from MySQL 8.0.xto 8.0.zis supported. MySQL 8.0.11 is the first GA status release within the MySQL 8.0 release series.
Installing a new version of MySQL may require upgrading these parts of the existing installation:
-
The
mysqlsystem schema, which contains tables that store information required by the MySQL server as it runs (see Section 5.3, “The mysql System Schema”).mysqlschema tables fall into two broad categories:-
Data dictionary tables, which store database object metadata.
-
System tables (that is, the remaining non-data dictionary tables), which are used for other operational purposes.
-
-
Other schemas, some of which are built in and may be considered “owned” by the server, and others which are not:
-
The Performance Schema,
INFORMATION_SCHEMA,ndbinfo, andsysschema. -
User schemas.
-
Two distinct version numbers are associated with parts of the installation that may require upgrading:
-
The data dictionary version. This applies to the data dictionary tables.
-
The server version, also known as the MySQL version. This applies to the system tables and objects in other schemas.
In both cases, the actual version applicable to the existing MySQL installation is stored in the data dictionary, and the current expected version is compiled into the new version of MySQL. When an actual version is lower than the current expected version, those parts of the installation associated with that version must be upgraded to the current version. If both versions indicate an upgrade is needed, the data dictionary upgrade must occur first.
As a reflection of the two distinct versions just mentioned, the upgrade occurs in two steps:
-
Step 1: Data dictionary upgrade.
This step upgrades:
-
The data dictionary tables in the
mysqlschema. If the actual data dictionary version is lower than the current expected version, the server creates data dictionary tables with updated definitions, copies persisted metadata to the new tables, atomically replaces the old tables with the new ones, and reinitializes the data dictionary. -
The Performance Schema,
INFORMATION_SCHEMA, andndbinfo.
-
-
Step 2: Server upgrade.
This step comprises all other upgrade tasks. If the server version of the existing MySQL installation is lower than that of the new installed MySQL version, everything else must be upgraded:
-
The system tables in the
mysqlschema (the remaining non-data dictionary tables). -
The
sysschema. -
User schemas.
-
The data dictionary upgrade (step 1) is the responsibility of the server, which performs this task as necessary at startup unless invoked with an option that prevents it from doing so. The option is --upgrade=NONE as of MySQL 8.0.16, --no-dd-upgrade prior to MySQL 8.0.16.
If the data dictionary is out of date but the server is prevented from upgrading it, the server will not run and exits with an error. For example:
[ERROR] [MY-013381] [Server] Server shutting down because upgrade is required, yet prohibited by the command line option '--upgrade=NONE'. [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
Some changes to the responsibility for step 2 occurred in MySQL 8.0.16:
-
Prior to MySQL 8.0.16, mysql_upgrade upgrades the Performance Schema, the
INFORMATION_SCHEMA, and the objects described in step 2. The DBA is expected to invoke mysql_upgrade manually after starting the server. -
As of MySQL 8.0.16, the server performs all tasks previously handled by mysql_upgrade. Although upgrading remains a two-step operation, the server performs them both, resulting in a simpler process.
Depending on the version of MySQL to which you are upgrading, the instructions in In-Place Upgrade and Logical Upgrade indicate whether the server performs all upgrade tasks or whether you must also invoke mysql_upgrade after server startup.
Because the server upgrades the Performance Schema, INFORMATION_SCHEMA, and the objects described in step 2 as of MySQL 8.0.16, mysql_upgrade is unneeded and is deprecated as of that version, and will be removed in a future MySQL version.
Most aspects of what occurs during step 2 are the same prior to and as of MySQL 8.0.16, although different command options may be needed to achieve a particular effect.
As of MySQL 8.0.16, the --upgrade server option controls whether and how the server performs an automatic upgrade at startup:
-
With no option or with
--upgrade=AUTO, the server upgrades anything it determines to be out of date (steps 1 and 2). -
With
--upgrade=NONE, the server upgrades nothing (skips steps 1 and 2), but also exits with an error if the data dictionary must be upgraded. It is not possible to run the server with an out-of-date data dictionary; the server insists on either upgrading it or exiting. -
With
--upgrade=MINIMAL, the server upgrades the data dictionary, the Performance Schema, and theINFORMATION_SCHEMA, if necessary (step 1). Note that following an upgrade with this option, Group Replication cannot be started, because system tables on which the replication internals depend are not updated, and reduced functionality might also be apparent in other areas. -
With
--upgrade=FORCE, the server upgrades the data dictionary, the Performance Schema, and theINFORMATION_SCHEMA, if necessary (step 1), and forces an upgrade of everything else (step 2). Expect server startup to take longer with this option because the server checks all objects in all schemas.
FORCE is useful to force step 2 actions to be performed if the server thinks they are not necessary. One way that FORCE differs from AUTO is that with FORCE, the server re-creates system tables such as help tables or time zone tables if they are missing.
The following list shows upgrade commands prior to MySQL 8.0.16 and the equivalent commands for MySQL 8.0.16 and higher:
-
Perform a normal upgrade (steps 1 and 2 as necessary):
-
Prior to MySQL 8.0.16: mysqld followed by mysql_upgrade
-
As of MySQL 8.0.16: mysqld
-
-
Perform only step 1 as necessary:
-
Prior to MySQL 8.0.16: It is not possible to perform all upgrade tasks described in step 1 while excluding those described in step 2. However, you can avoid upgrading user schemas and the
sysschema using mysqld followed by mysql_upgrade with the--upgrade-system-tablesand--skip-sys-schemaoptions. -
As of MySQL 8.0.16: mysqld --upgrade=MINIMAL
-
-
Perform step 1 as necessary, and force step 2:
-
Prior to MySQL 8.0.16: mysqld followed by mysql_upgrade --force
-
As of MySQL 8.0.16: mysqld --upgrade=FORCE
-
Prior to MySQL 8.0.16, certain mysql_upgrade options affect the actions it performs. The following table shows which server --upgrade option values to use as of MySQL 8.0.16 to achieve similar effects. (These are not necessarily exact equivalents because a given --upgrade option value may have additional effects.)
| mysql_upgrade Option | Server Option |
|---|---|
--skip-sys-schema |
--upgrade=NONE or --upgrade=MINIMAL |
--upgrade-system-tables |
--upgrade=NONE or --upgrade=MINIMAL |
--force |
--upgrade=FORCE |
Additional notes about what occurs during upgrade step 2:
-
Step 2 installs the
sysschema if it is not installed, and upgrades it to the current version otherwise. An error occurs if asysschema exists but has noversionview, on the assumption that its absence indicates a user-created schema:A sys schema exists with no sys.version view. If you have a user created sys schema, this must be renamed for the upgrade to succeed.
To upgrade in this case, remove or rename the existing
sysschema first. Then perform the upgrade procedure again. (It may be necessary to force step 2.)To prevent the
sysschema check:-
As of MySQL 8.0.16: Start the server with the
--upgrade=NONEor--upgrade=MINIMALoption. -
Prior to MySQL 8.0.16: Invoke mysql_upgrade with the
--skip-sys-schemaoption.
-
-
Step 2 processes all tables in all user schemas as necessary. Table checking might take a long time to complete. Each table is locked and therefore unavailable to other sessions while it is being processed. Check and repair operations can be time-consuming, particularly for large tables. Table checking uses the
FOR UPGRADEoption of theCHECK TABLEstatement. For details about what this option entails, see Section 13.7.3.2, “CHECK TABLE Statement”.To prevent table checking:
-
As of MySQL 8.0.16: Start the server with the
--upgrade=NONEor--upgrade=MINIMALoption. -
Prior to MySQL 8.0.16: Invoke mysql_upgrade with the
--upgrade-system-tablesoption.
To force table checking:
-
As of MySQL 8.0.16: Start the server with the
--upgrade=FORCEoption. -
Prior to MySQL 8.0.16: Invoke mysql_upgrade with the
--forceoption.
-
-
Step 2 saves the MySQL version number in a file named
mysql_upgrade_infoin the data directory.To ignore the
mysql_upgrade_infofile and perform the check regardless:-
As of MySQL 8.0.16: Start the server with the
--upgrade=FORCEoption. -
Prior to MySQL 8.0.16: Invoke mysql_upgrade with the
--forceoption.
NoteThe
mysql_upgrade_infofile is deprecated and will be removed in a future MySQL version. -
-
Step 2 marks all checked and repaired tables with the current MySQL version number. This ensures that the next time upgrade checking occurs with the same version of the server, it can be determined whether there is any need to check or repair a given table again.
-
Step 2 upgrades the system tables to ensure that they have the current structure. This is true whether the server or mysql_upgrade performs the step. With respect to the content of the help tables and time zone tables, mysql_upgrade does not load either type of table, whereas the server loads the help tables, but not the time zone tables. (That is, prior to MySQL 8.0.16, the server loads the help tables only at data directory initialization time. As of MySQL 8.0.16, it loads the help tables at initialization and upgrade time.) The procedure for loading time zone tables is platform dependent and requires decision making by the DBA, so it cannot be done automatically.
Before upgrading to MySQL 8.0, review the changes described in this section to identify those that apply to your current MySQL installation and applications. Perform any recommended actions.
Changes marked as Incompatible change are incompatibilities with earlier versions of MySQL, and may require your attention before upgrading. Our aim is to avoid these changes, but occasionally they are necessary to correct problems that would be worse than an incompatibility between releases. If an upgrade issue applicable to your installation involves an incompatibility, follow the instructions given in the description.
MySQL Server 8.0 incorporates a global data dictionary containing information about database objects in transactional tables. In previous MySQL series, dictionary data was stored in metadata files and nontransactional system tables. As a result, the upgrade procedure requires that you verify the upgrade readiness of your installation by checking specific prerequisites. For more information, see Section 2.11.5, “Preparing Your Installation for Upgrade”. A data dictionary-enabled server entails some general operational differences; see Section 14.7, “Data Dictionary Usage Differences”.
The caching_sha2_password and sha256_password authentication plugins provide more secure password encryption than the mysql_native_password plugin, and caching_sha2_password provides better performance than sha256_password. Due to these superior security and performance characteristics of caching_sha2_password, it is as of MySQL 8.0 the preferred authentication plugin, and is also the default authentication plugin rather than mysql_native_password. This change affects both the server and the libmysqlclient client library:
-
For the server, the default value of the
default_authentication_pluginsystem variable changes frommysql_native_passwordtocaching_sha2_password.This change applies only to new accounts created after installing or upgrading to MySQL 8.0 or higher. For accounts already existing in an upgraded installation, their authentication plugin remains unchanged. Existing users who wish to switch to
caching_sha2_passwordcan do so using theALTER USERstatement:ALTER USER
userIDENTIFIED WITH caching_sha2_password BY 'password'; -
The
libmysqlclientlibrary treatscaching_sha2_passwordas the default authentication plugin rather thanmysql_native_password.
The following sections discuss the implications of the more prominent role of caching_sha2_password:
caching_sha2_password Compatibility Issues and Solutions
If your MySQL installation must serve pre-8.0 clients and you encounter compatibility issues after upgrading to MySQL 8.0 or higher, the simplest way to address those issues and restore pre-8.0 compatibility is to reconfigure the server to revert to the previous default authentication plugin (mysql_native_password). For example, use these lines in the server option file:
[mysqld] default_authentication_plugin=mysql_native_password
That setting enables pre-8.0 clients to connect to 8.0 servers until such time as the clients and connectors in use at your installation are upgraded to know about caching_sha2_password. However, the setting should be viewed as temporary, not as a long term or permanent solution, because it causes new accounts created with the setting in effect to forego the improved authentication security provided by caching_sha2_password.
The use of caching_sha2_password offers more secure password hashing than mysql_native_password (and consequent improved client connection authentication). However, it also has compatibility implications that may affect existing MySQL installations:
-
Clients and connectors that have not been updated to know about
caching_sha2_passwordmay have trouble connecting to a MySQL 8.0 server configured withcaching_sha2_passwordas the default authentication plugin, even to use accounts that do not authenticate withcaching_sha2_password. This issue occurs because the server specifies the name of its default authentication plugin to clients. If a client or connector is based on a client/server protocol implementation that does not gracefully handle an unrecognized default authentication plugin, it may fail with an error such as one of these:Authentication plugin 'caching_sha2_password' is not supported
Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image not found
Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
For information about writing connectors to gracefully handle requests from the server for unknown default authentication plugins, see Authentication Plugin Connector-Writing Considerations.
-
Clients that use an account that authenticates with
caching_sha2_passwordmust use either a secure connection (made using TCP using TLS/SSL credentials, a Unix socket file, or shared memory), or an unencrypted connection that supports password exchange using an RSA key pair. This security requirement does not apply tomysql_native_passsword, so the switch tocaching_sha2_passwordmay require additional configuration (see Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”). However, client connections in MySQL 8.0 prefer use of TLS/SSL by default, so clients that already conform to that preference may need no additional configuration. -
Clients and connectors that have not been updated to know about
caching_sha2_passwordcannot connect to accounts that authenticate withcaching_sha2_passwordbecause they do not recognize this plugin as valid. (This is a particular instance of how client/server authentication plugin compatibility requirements apply, as discussed at Authentication Plugin Client/Server Compatibility.) To work around this issue, relink clients againstlibmysqlclientfrom MySQL 8.0 or higher, or obtain an updated connector that recognizescaching_sha2_password. -
Because
caching_sha2_passwordis also now the default authentication plugin in thelibmysqlclientclient library, authentication requires an extra round trip in the client/server protocol for connections from MySQL 8.0 clients to accounts that usemysql_native_password(the previous default authentication plugin), unless the client program is invoked with a--default-auth=mysql_native_passwordoption.
The libmysqlclient client library for pre-8.0 MySQL versions is able to connect to MySQL 8.0 servers (except for accounts that authenticate with caching_sha2_password). That means pre-8.0 clients based on libmysqlclient should also be able to connect. Examples:
-
Standard MySQL clients such as mysql and mysqladmin are
libmysqlclient-based. -
The DBD::mysql driver for Perl DBI is
libmysqlclient-based. -
MySQL Connector/Python has a C Extension module that is
libmysqlclient-based. To use it, include theuse_pure=Falseoption at connect time.
When an existing MySQL 8.0 installation is upgraded to MySQL 8.0.4 or higher, some older libmysqlclient-based clients may “automatically” upgrade if they are dynamically linked, because they use the new client library installed by the upgrade. For example, if the DBD::mysql driver for Perl DBI uses dynamic linking, it can use the libmysqlclient in place after an upgrade to MySQL 8.0.4 or higher, with this result:
-
Prior to the upgrade, DBI scripts that use DBD::mysql can connect to a MySQL 8.0 server, except for accounts that authenticate with
caching_sha2_password. -
After the upgrade, the same scripts become able to use
caching_sha2_passwordaccounts as well.
However, the preceding results occur because libmysqlclient instances from MySQL 8.0 installations prior to 8.0.4 are binary compatible: They both use a shared library major version number of 21. For clients linked to libmysqlclient from MySQL 5.7 or older, they link to a shared library with a different version number that is not binary compatible. In this case, the client must be recompiled against libmysqlclient from 8.0.4 or higher for full compatibility with MySQL 8.0 servers and caching_sha2_password accounts.
MySQL Connector/J 5.1 through 8.0.8 is able to connect to MySQL 8.0 servers, except for accounts that authenticate with caching_sha2_password. (Connector/J 8.0.9 or higher is required to connect to caching_sha2_password accounts.)
Clients that use an implementation of the client/server protocol other than libmysqlclient may need to be upgraded to a newer version that understands the new authentication plugin. For example, in PHP, MySQL connectivity usually is based on mysqlnd, which currently does not know about caching_sha2_password. Until an updated version of mysqlnd is available, the way to enable PHP clients to connect to MySQL 8.0 is to reconfigure the server to revert to mysql_native_password as the default authentication plugin, as previously discussed.
If a client or connector supports an option to explicitly specify a default authentication plugin, use it to name a plugin other than caching_sha2_password. Examples:
-
Some MySQL clients support a
--default-authoption. (Standard MySQL clients such as mysql and mysqladmin support this option but can successfully connect to 8.0 servers without it. However, other clients may support a similar option. If so, it is worth trying it.) -
Programs that use the
libmysqlclientC API can call themysql_options()function with theMYSQL_DEFAULT_AUTHoption. -
MySQL Connector/Python scripts that use the native Python implementation of the client/server protocol can specify the
auth_pluginconnection option. (Alternatively, use the Connector/Python C Extension, which is able to connect to MySQL 8.0 servers without the need forauth_plugin.)
caching_sha2_password-Compatible Clients and Connectors
If a client or connector is available that has been updated to know about caching_sha2_password, using it is the best way to ensure compatibility when connecting to a MySQL 8.0 server configured with caching_sha2_password as the default authentication plugin.
These clients and connectors have been upgraded to support caching_sha2_password:
-
The
libmysqlclientclient library in MySQL 8.0 (8.0.4 or higher). Standard MySQL clients such as mysql and mysqladmin arelibmysqlclient-based, so they are compatible as well. -
The
libmysqlclientclient library in MySQL 5.7 (5.7.23 or higher). Standard MySQL clients such as mysql and mysqladmin arelibmysqlclient-based, so they are compatible as well. -
MySQL Connector/C++ 1.1.11 or higher or 8.0.7 or higher.
-
MySQL Connector/J 8.0.9 or higher.
-
MySQL Connector/NET 8.0.10 or higher (through the classic MySQL protocol).
-
MySQL Connector/Node.js 8.0.9 or higher.
-
PHP: the X DevAPI PHP extension (mysql_xdevapi) supports
caching_sha2_password.PHP: the PDO_MySQL and ext/mysqli extensions do not support
caching_sha2_password. In addition, when used with PHP versions before 7.1.16 and PHP 7.2 before 7.2.4, they fail to connect withdefault_authentication_plugin=caching_sha2_passwordeven ifcaching_sha2_passwordis not used.
caching_sha2_password and the root Administrative Account
For upgrades to MySQL 8.0, the authentication plugin existing accounts remains unchanged, including the plugin for the 'root'@'localhost' administrative account.
For new MySQL 8.0 installations, when you initialize the data directory (using the instructions at Section 2.10.1, “Initializing the Data Directory”), the 'root'@'localhost' account is created, and that account uses caching_sha2_password by default. To connect to the server following data directory initialization, you must therefore use a client or connector that supports caching_sha2_password. If you can do this but prefer that the root account use mysql_native_password after installation, install MySQL and initialize the data directory as you normally would. Then connect to the server as root and use ALTER USER as follows to change the account authentication plugin and password:
ALTER USER 'root'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'password';
If the client or connector that you use does not yet support caching_sha2_password, you can use a modified data directory-initialization procedure that associates the root account with mysql_native_password as soon as the account is created. To do so, use either of these techniques:
-
Supply a
--default-authentication-plugin=mysql_native_passwordoption along with--initializeor--initialize-insecure. -
Set
default_authentication_plugintomysql_native_passwordin an option file, and name that option file using a--defaults-fileoption along with--initializeor--initialize-insecure. (In this case, if you continue to use that option file for subsequent server startups, new accounts will be created withmysql_native_passwordrather thancaching_sha2_passwordunless you remove thedefault_authentication_pluginsetting from the option file.)
caching_sha2_password and Replication
In replication scenarios for which all servers have been upgraded to MySQL 8.0.4 or higher, slave/replica connections to master/primary servers can use accounts that authenticate with caching_sha2_password. For such connections, the same requirement applies as for other clients that use accounts that authenticate with caching_sha2_password: Use a secure connection or RSA-based password exchange.
To connect to a caching_sha2_password account for master/slave replication:
-
Use any of the following
CHANGE MASTER TOoptions:MASTER_SSL = 1 GET_MASTER_PUBLIC_KEY = 1 MASTER_PUBLIC_KEY_PATH='
path to RSA public key file' -
Alternatively, you can use the RSA public key-related options if the required keys are supplied at server startup.
To connect to a caching_sha2_password account for Group Replication:
-
For MySQL built using OpenSSL, set any of the following system variables:
SET GLOBAL group_replication_recovery_use_ssl = ON; SET GLOBAL group_replication_recovery_get_public_key = 1; SET GLOBAL group_replication_recovery_public_key_path = '
path to RSA public key file'; -
Alternatively, you can use the RSA public key-related options if the required keys are supplied at server startup.
-
Incompatible change: A MySQL storage engine is now responsible for providing its own partitioning handler, and the MySQL server no longer provides generic partitioning support.
InnoDBandNDBare the only storage engines that provide a native partitioning handler that is supported in MySQL 8.0. A partitioned table using any other storage engine must be altered—either to convert it toInnoDBorNDB, or to remove its partitioning—before upgrading the server, else it cannot be used afterwards.For information about converting
MyISAMtables toInnoDB, see Section 15.6.1.5, “Converting Tables from MyISAM to InnoDB”.A table creation statement that would result in a partitioned table using a storage engine without such support fails with an error (ER_CHECK_NOT_IMPLEMENTED) in MySQL 8.0. If you import databases from a dump file created in MySQL 5.7 (or earlier) using mysqldump into a MySQL 8.0 server, you must make sure that any statements creating partitioned tables do not also specify an unsupported storage engine, either by removing any references to partitioning, or by specifying the storage engine as
InnoDBor allowing it to be set asInnoDBby default.NoteThe procedure given at Section 2.11.5, “Preparing Your Installation for Upgrade”, describes how to identify partitioned tables that must be altered before upgrading to MySQL 8.0.
See Section 23.6.2, “Partitioning Limitations Relating to Storage Engines”, for further information.
-
Incompatible change: Several server error codes are not used and have been removed (for a list, see Features Removed in MySQL 8.0). Applications that test specifically for any of them should be updated.
-
Important change: The default character set has changed from
latin1toutf8mb4. These system variables are affected:-
The default value of the
character_set_serverandcharacter_set_databasesystem variables has changed fromlatin1toutf8mb4. -
The default value of the
collation_serverandcollation_databasesystem variables has changed fromlatin1_swedish_citoutf8mb4_0900_ai_ci.
As a result, the default character set and collation for new objects differ from previously unless an explicit character set and collation are specified. This includes databases and objects within them, such as tables, views, and stored programs. Assuming that the previous defaults were used, one way to preserve them is to start the server with these lines in the
my.cnffile:[mysqld] character_set_server=latin1 collation_server=latin1_swedish_ci
In a replicated setting, when upgrading from MySQL 5.7 to 8.0, it is advisable to change the default character set back to the character set used in MySQL 5.7 before upgrading. After the upgrade is completed, the default character set can be changed to
utf8mb4. -
-
Incompatible change: As of MySQL 8.0.11, it is prohibited to start the server with a
lower_case_table_namessetting that is different from the setting used when the server was initialized. The restriction is necessary because collations used by various data dictionary table fields are based on thelower_case_table_namessetting that was defined when the server was initialized, and restarting the server with a different setting would introduce inconsistencies with respect to how identifiers are ordered and compared.
-
In MySQL 8.0.11, several deprecated features related to account management have been removed, such as use of the
GRANTstatement to modify nonprivilege characteristics of user accounts, theNO_AUTO_CREATE_USERSQL mode, thePASSWORD()function, and theold_passwordssystem variable.Replication from MySQL 5.7 to 8.0 of statements that refer to these removed features can cause replication failure. Applications that use any of the removed features should be revised to avoid them and use alternatives when possible, as described in Features Removed in MySQL 8.0.
To avoid a startup failure on MySQL 8.0, remove any instance of
NO_AUTO_CREATE_USERfromsql_modesystem variable settings in MySQL option files.Loading a dump file that includes the
NO_AUTO_CREATE_USERSQL mode in stored program definitions into a MySQL 8.0 server causes a failure. As of MySQL 5.7.24 and MySQL 8.0.13, mysqldump removesNO_AUTO_CREATE_USERfrom stored program definitions. Dump files created with an earlier version ofmysqldumpmust be modified manually to remove instances ofNO_AUTO_CREATE_USER. -
In MySQL 8.0.11, these deprecated compatibility SQL modes were removed:
DB2,MAXDB,MSSQL,MYSQL323,MYSQL40,ORACLE,POSTGRESQL,NO_FIELD_OPTIONS,NO_KEY_OPTIONS,NO_TABLE_OPTIONS. They can no longer be assigned to thesql_modesystem variable or used as permitted values for the mysqldump--compatibleoption.Removal of
MAXDBmeans that theTIMESTAMPdata type forCREATE TABLEorALTER TABLEis no longer treated asDATETIME.Replication from MySQL 5.7 to 8.0 of statements that refer to the removed SQL modes can cause replication failure. This includes replication of
CREATEstatements for stored programs (stored procedures and functions, triggers, and events) that are executed while the currentsql_modevalue includes any of the removed modes. Applications that use any of the removed modes should be revised to avoid them. -
As of MySQL 8.0.3, spatial data types permit an
SRIDattribute, to explicitly indicate the spatial reference system (SRS) for values stored in the column. See Section 11.4.1, “Spatial Data Types”.A spatial column with an explicit
SRIDattribute is SRID-restricted: The column takes only values with that ID, andSPATIALindexes on the column become subject to use by the optimizer. The optimizer ignoresSPATIALindexes on spatial columns with noSRIDattribute. See Section 8.3.3, “SPATIAL Index Optimization”. If you want the optimizer to considerSPATIALindexes on spatial columns that are not SRID-restricted, each such column should be modified:-
Verify that all values within the column have the same SRID. To determine the SRIDs contained in a geometry column
col_name, use the following query:SELECT DISTINCT ST_SRID(
col_name) FROMtbl_name;If the query returns more than one row, the column contains a mix of SRIDs. In that case, modify its contents so all values have the same SRID.
-
Redefine the column to have an explicit
SRIDattribute. -
Recreate the
SPATIALindex.
-
-
Several spatial functions were removed in MySQL 8.0.0 due to a spatial function namespace change that implemented an
ST_prefix for functions that perform an exact operation, or anMBRprefix for functions that perform an operation based on minimum bounding rectangles. The use of removed spatial functions in generated column definitions could cause an upgrade failure. Before upgrading, run mysqlcheck --check-upgrade for removed spatial functions and replace any that you find with theirST_orMBRnamed replacements. For a list of removed spatial functions, refer to Features Removed in MySQL 8.0. -
The
BACKUP_ADMINprivilege is automatically granted to users with theRELOADprivilege when performing an in-place upgrade to MySQL 8.0.3 or higher. -
From MySQL 8.0.13, because of differences between row-based or mixed replication mode and statement-based replication mode in the way that temporary tables are handled, there are new restrictions on switching the binary logging format at runtime.
-
SET @@SESSION.binlog_formatcannot be used if the session has any open temporary tables. -
SET @@global.binlog_formatandSET @@persist.binlog_formatcannot be used if any replication channel has any open temporary tables.SET @@persist_only.binlog_formatis allowed if replication channels have open temporary tables, because unlikePERSIST,PERSIST_ONLYdoes not modify the runtime global system variable value. -
SET @@global.binlog_formatandSET @@persist.binlog_formatcannot be used if any replication channel applier is running. This is because the change only takes effect on a replication channel when its applier is restarted, at which time the replication channel might have open temporary tables. This behavior is more restrictive than before.SET @@persist_only.binlog_formatis allowed if any replication channel applier is running.
-
-
INFORMATION_SCHEMAviews based onInnoDBsystem tables were replaced by internal system views on data dictionary tables. AffectedInnoDBINFORMATION_SCHEMAviews were renamed:Table 2.15 Renamed InnoDB Information Schema Views
Old Name New Name INNODB_SYS_COLUMNSINNODB_COLUMNSINNODB_SYS_DATAFILESINNODB_DATAFILESINNODB_SYS_FIELDSINNODB_FIELDSINNODB_SYS_FOREIGNINNODB_FOREIGNINNODB_SYS_FOREIGN_COLSINNODB_FOREIGN_COLSINNODB_SYS_INDEXESINNODB_INDEXESINNODB_SYS_TABLESINNODB_TABLESINNODB_SYS_TABLESPACESINNODB_TABLESPACESINNODB_SYS_TABLESTATSINNODB_TABLESTATSINNODB_SYS_VIRTUALINNODB_VIRTUAL
After upgrading to MySQL 8.0.3 or higher, update any scripts that reference previous
InnoDBINFORMATION_SCHEMAview names. -
The zlib library version bundled with MySQL was raised from version 1.2.3 to version 1.2.11.
The zlib
compressBound()function in zlib 1.2.11 returns a slightly higher estimate of the buffer size required to compress a given length of bytes than it did in zlib version 1.2.3. ThecompressBound()function is called byInnoDBfunctions that determine the maximum row size permitted when creating compressedInnoDBtables or inserting and updating rows in compressedInnoDBtables. As a result,CREATE TABLE ... ROW_FORMAT=COMPRESSED,INSERT, andUPDATEoperations with row sizes very close to the maximum row size that were successful in earlier releases could now fail. To avoid this issue, testCREATE TABLEstatements for compressedInnoDBtables with large rows on a MySQL 8.0 test instance prior to upgrading. -
With the introduction of the
--innodb-directoriesfeature, the location of file-per-table and general tablespace files created with an absolute path or in a location outside of the data directory should be added to theinnodb_directoriesargument value. Otherwise,InnoDBis not able to locate these files during recovery. To view tablespace file locations, query theINFORMATION_SCHEMA.FILEStable:SELECT TABLESPACE_NAME, FILE_NAME FROM INFORMATION_SCHEMA.FILES \G
-
Undo logs can no longer reside in the system tablespace. In MySQL 8.0, undo logs reside in two undo tablespaces by default. For more information, see Section 15.6.3.4, “Undo Tablespaces”.
When upgrading from MySQL 5.7 to MySQL 8.0, any undo tablespaces that exist in the MySQL 5.7 instance are removed and replaced by two new default undo tablespaces. Default undo tablespaces are created in the location defined by the
innodb_undo_directoryvariable. If theinnodb_undo_directoryvariable is undefined, undo tablespaces are created in the data directory. Upgrade from MySQL 5.7 to MySQL 8.0 requires a slow shutdown which ensures that undo tablespaces in the MySQL 5.7 instance are empty, permitting them to be removed safely.When upgrading to MySQL 8.0.14 or later from an earlier MySQL 8.0 release, undo tablespaces that exist in the pre-upgrade instance as a result of an
innodb_undo_tablespacessetting greater than 2 are treated as user-defined undo tablespaces, which can be deactivated and dropped usingALTER UNDO TABLESPACEandDROP UNDO TABLESPACEsyntax, respectively, after upgrading. Upgrade within the MySQL 8.0 release series may not always require a slow shutdown which means that existing undo tablespaces could contain undo logs. Therefore, existing undo tablespaces are not removed by the upgrade process. -
Incompatible change: As of MySQL 8.0.17, the
CREATE TABLESPACE ... ADD DATAFILEclause does not permit circular directory references. For example, the circular directory reference (/../) in the following statement is not permitted:CREATE TABLESPACE ts1 ADD DATAFILE ts1.ibd '
any_directory/../ts1.ibd';An exception to the restriction exists on Linux, where a circular directory reference is permitted if the preceding directory is a symbolic link. For example, the data file path in the example above is permitted if
any_directoryis a symbolic link. (It is still permitted for data file paths to begin with '../'.)To avoid upgrade issues, remove any circular directory references from tablespace data file paths before upgrading to MySQL 8.0.17 or higher. To inspect tablespace paths, query the
INFORMATION_SCHEMA.INNODB_DATAFILEStable. -
Due to a regression introduced in MySQL 8.0.14, in-place upgrade on a case sensitive file system from MySQL 5.7 or a MySQL 8.0 release prior to MySQL 8.0.14 to MySQL 8.0.16 failed for instances with partitioned tables and
lower_case_table_names=1. The failure was caused by a case mismatch issue related to partitioned table file names. The fix that introduced the regression was reverted, which permits upgrades to MySQL 8.0.17 from MySQL 5.7 or MySQL 8.0 releases prior to MySQL 8.0.14 to function as normal. However, the regression is still present in the MySQL 8.0.14, 8.0.15, and 8.0.16 releases.In-place upgrade on a case sensitive file system from MySQL 8.0.14, 8.0.15, or 8.0.16 to MySQL 8.0.17 fails with the following error when starting the server after upgrading binaries or packages to MySQL 8.0.17 if partitioned tables are present and
lower_case_table_names=1:Upgrading from server version
version_numberwith partitioned tables and lower_case_table_names == 1 on a case sensitive file system may cause issues, and is therefore prohibited. To upgrade anyway, restart the new server version with the command line option 'upgrade=FORCE'. When upgrade is completed, please execute 'RENAME TABLEpart_table_nameTOnew_table_name; RENAME TABLEnew_table_nameTOpart_table_name;' for each of the partitioned tables. Please see the documentation for further information.If you encounter this error when upgrading to MySQL 8.0.17, perform the following workaround:
-
Restart the server with
--upgrade=forceto force the upgrade operation to proceed. -
Identify partitioned table file names with lowercase partition name delimiters
(#p#or#sp#):mysql> SELECT FILE_NAME FROM INFORMATION_SCHEMA.FILES WHERE FILE_NAME LIKE '%#p#%' OR FILE_NAME LIKE '%#sp#%';
-
For each file identified, rename the associated table using a temporary name, then rename the table back to its original name.
mysql> RENAME TABLE
table_nameTOtemporary_table_name; mysql> RENAME TABLEtemporary_table_nameTOtable_name; -
Verify that there are no partitioned table file names lowercase partition name delimiters (an empty result set should be returned).
mysql>
SELECT FILE_NAME FROM INFORMATION_SCHEMA.FILES WHERE FILE_NAME LIKE '%#p#%' OR FILE_NAME LIKE '%#sp#%';Empty set (0.00 sec) -
Run
ANALYZE TABLEon each renamed table to update the optimizer statistics in themysql.innodb_index_statsandmysql.innodb_table_statstables.
Because of the regression still present in the MySQL 8.0.14, 8.0.15, and 8.0.16 releases, importing partitioned tables from MySQL 8.0.14, 8.0.15, or 8.0.16 to MySQL 8.0.17 is not supported on case sensitive file systems where
lower_case_table_names=1. Attempting to do so results in a “Tablespace is missing for table” error. -
-
MySQL uses delimiter strings when constructing tablespace names and file names for table partitions. A “
#p#” delimiter string precedes partition names, and an “#sp#” delimiter string precedes subpartition names, as shown:schema_name.table_name#p#partition_name#sp#subpartition_nametable_name#p#partition_name#sp#subpartition_name.ibdHistorically, delimiter strings have been uppercase (
#P#and#SP#) on case-sensitive file systems such as Linux, and lowercase (#p#and#sp#) on case-insensitive file systems such as Windows. As of MySQL 8.0.19, delimiter strings are lowercase on all file systems. This change prevents issues when migrating data directories between case-sensitive and case-insensitive file systems. Uppercase delimiter strings are no longer used.Additionally, partition tablespace names and file names generated based on user-specified partition or subpartition names, which can be specified in uppercase or lowercase, are now generated (and stored internally) in lowercase regardless of the
lower_case_table_namessetting to ensure case-insensitivity. For example, if a table partition is created with the namePART_1, the tablespace name and file name are generated in lowercase:schema_name.table_name#p#part_1table_name#p#part_1.ibdDuring upgrade, MySQL checks and modifies if necessary:
-
Partition file names on disk and in the data dictionary to ensure lowercase delimiters and partition names.
-
Partition metadata in the data dictionary for related issues introduced by previous bug fixes.
-
InnoDBstatistics data for related issues introduced by previous bug fixes.
During tablespace import operations, partition tablespace file names on disk are checked and modified if necessary to ensure lowercase delimiters and partition names.
-
-
Incompatible change: As of MySQL 8.0.13, the deprecated
ASCorDESCqualifiers forGROUP BYclauses have been removed. Queries that previously relied onGROUP BYsorting may produce results that differ from previous MySQL versions. To produce a given sort order, provide anORDER BYclause.Queries and stored program definitions from MySQL 8.0.12 or lower that use
ASCorDESCqualifiers forGROUP BYclauses should be amended. Otherwise, upgrading to MySQL 8.0.13 or higher may fail, as may replicating to MySQL 8.0.13 or higher slave servers. -
Some keywords may be reserved in MySQL 8.0 that were not reserved in MySQL 5.7. See Section 9.3, “Keywords and Reserved Words”. This can cause words previously used as identifiers to become illegal. To fix affected statements, use identifier quoting. See Section 9.2, “Schema Object Names”.
-
After upgrading, it is recommended that you test optimizer hints specified in application code to ensure that the hints are still required to achieve the desired optimization strategy. Optimizer enhancements can sometimes render certain optimizer hints unnecessary. In some cases, an unnecessary optimizer hint may even be counterproductive.
-
Incompatible change: In MySQL 5.7, specifying a
FOREIGN KEYdefinition for anInnoDBtable without aCONSTRAINTclause, or specifying thesymbolCONSTRAINTkeyword without asymbol, causesInnoDBto use a generated constraint name. That behavior changed in MySQL 8.0, withInnoDBusing theFOREIGN KEYvalue instead of a generated name. Because constraint names must be unique per schema (database), the change caused errors due to foreign key index names that were not unique per schema. To avoid such errors, the new constraint naming behavior has been reverted in MySQL 8.0.16, andindex_nameInnoDBonce again uses a generated constraint name.For consistency with
InnoDB,NDBreleases based on MySQL 8.0.16 or higher use a generated constraint name if theCONSTRAINTclause is not specified, or thesymbolCONSTRAINTkeyword is specified without asymbol.NDBreleases based on MySQL 5.7 and earlier MySQL 8.0 releases used theFOREIGN KEYvalue.index_nameThe changes described above may introduce incompatibilities for applications that depend on the previous foreign key constraint naming behavior.
Before upgrading to the latest MySQL 8.0 release, ensure the upgrade readiness of your current MySQL 5.7 or MySQL 8.0 server instance by performing the preliminary checks described below. The upgrade process may fail otherwise.
The same checks and others can be performed using the MySQL Shell upgrade checker utility. For more information, see Upgrade Checker Utility.
Preliminary checks:
-
The following issues must not be present:
-
There must be no tables that use obsolete data types or functions.
In-place upgrade to MySQL 8.0 is not supported if tables contain old temporal columns in pre-5.6.4 format (
TIME,DATETIME, andTIMESTAMPcolumns without support for fractional seconds precision). If your tables still use the old temporal column format, upgrade them usingREPAIR TABLEbefore attempting an in-place upgrade to MySQL 8.0. For more information, see Server Changes. -
There must be no orphan
.frmfiles. -
Triggers must not have a missing or empty definer or an invalid creation context (indicated by the
character_set_client,collation_connection,Database Collationattributes displayed bySHOW TRIGGERSor theINFORMATION_SCHEMATRIGGERStable). Any such triggers must be dumped and restored to fix the issue.
To check for these issues, execute this command:
mysqlcheck -u root -p --all-databases --check-upgrade
If mysqlcheck reports any errors, correct the issues.
-
-
There must be no partitioned tables that use a storage engine that does not have native partitioning support. To identify such tables, execute this query:
SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE ENGINE NOT IN ('innodb', 'ndbcluster') AND CREATE_OPTIONS LIKE '%partitioned%';Any table reported by the query must be altered to use
InnoDBor be made nonpartitioned. To change a table storage engine toInnoDB, execute this statement:ALTER TABLE
table_nameENGINE = INNODB;For information about converting
MyISAMtables toInnoDB, see Section 15.6.1.5, “Converting Tables from MyISAM to InnoDB”.To make a partitioned table nonpartitioned, execute this statement:
ALTER TABLE
table_nameREMOVE PARTITIONING; -
Some keywords may be reserved in MySQL 8.0 that were not reserved previously. See Section 9.3, “Keywords and Reserved Words”. This can cause words previously used as identifiers to become illegal. To fix affected statements, use identifier quoting. See Section 9.2, “Schema Object Names”.
-
There must be no tables in the MySQL 5.7
mysqlsystem database that have the same name as a table used by the MySQL 8.0 data dictionary. To identify tables with those names, execute this query: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' );
Any tables reported by the query must be dropped or renamed (use
RENAME TABLE). This may also entail changes to applications that use the affected tables. -
There must be no tables that have foreign key constraint names longer than 64 characters. Use this query to identify tables with constraint names that are too long:
SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME IN (SELECT LEFT(SUBSTR(ID,INSTR(ID,'/')+1), INSTR(SUBSTR(ID,INSTR(ID,'/')+1),'_ibfk_')-1) FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN WHERE LENGTH(SUBSTR(ID,INSTR(ID,'/')+1))>64);For a table with a constraint name that exceeds 64 characters, drop the constraint and add it back with constraint name that does not exceed 64 characters (use
ALTER TABLE). -
The must be no obsolete SQL modes defined in your
sql_modesystem variable setting. Attempting to use an obsolete SQL mode will cause a startup failure on MySQL 8.0. Applications that use obsolete SQL modes should also be revised to avoid them. For information about SQL modes removed in MySQL 8.0, see Server Changes. -
There must be no views with explicitly defined columns names that exceed 64 characters (views with column names up to 255 characters were permitted in MySQL 5.7). To avoid upgrade errors, such views should be altered before upgrading. Currently, the only method of identify views with column names that exceed 64 characters is to inspect the view definition using
SHOW CREATE VIEW. You can also inspect view definitions by querying theINFORMATION_SCHEMA.VIEWStable. -
There must be no tables or stored procedures with individual
ENUMorSETcolumn elements that exceed 255 characters or 1020 bytes in length. Prior to MySQL 8.0, the maximum combined length ofENUMorSETcolumn elements was 64K. In MySQL 8.0, the maximum character length of an individualENUMorSETcolumn element is 255 characters, and the maximum byte length is 1020 bytes. (The 1020 byte limit supports multitibyte character sets). Before upgrading to MySQL 8.0, modify anyENUMorSETcolumn elements that exceed the new limits. Failing to do so causes the upgrade to fail with an error. -
Before upgrading to MySQL 8.0.13 or higher, there must be no table partitions that reside in shared
InnoDBtablespaces, which include the system tablespace and general tablespaces. Identify table partitions in shared tablespaces by queryingINFORMATION_SCHEMA:If upgrading from MySQL 5.7, run this query:
SELECT DISTINCT NAME, SPACE, SPACE_TYPE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE '%#P#%' AND SPACE_TYPE NOT LIKE 'Single';
If upgrading from an earlier MySQL 8.0 release, run this query:
SELECT DISTINCT NAME, SPACE, SPACE_TYPE FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME LIKE '%#P#%' AND SPACE_TYPE NOT LIKE 'Single';
Move table partitions from shared tablespaces to file-per-table tablespaces using
ALTER TABLE ... REORGANIZE PARTITION:ALTER TABLE
table_nameREORGANIZE PARTITIONpartition_nameINTO (partition_definitionTABLESPACE=innodb_file_per_table); -
There must be no queries and stored program definitions from MySQL 8.0.12 or lower that use
ASCorDESCqualifiers forGROUP BYclauses. Otherwise, upgrading to MySQL 8.0.13 or higher may fail, as may replicating to MySQL 8.0.13 or higher slave servers. For additional details, see SQL Changes. -
Your MySQL 5.7 installation must not use features that are not supported by MySQL 8.0. Any changes here are necessarily installation specific, but the following example illustrates the kind of thing to look for:
Some server startup options and system variables have been removed in MySQL 8.0. See Features Removed in MySQL 8.0, and Section 1.5, “Server and Status Variables and Options Added, Deprecated, or Removed in MySQL 8.0”. If you use any of these, an upgrade requires configuration changes.
Example: Because the data dictionary provides information about database objects, the server no longer checks directory names in the data directory to find databases. Consequently, the
--ignore-db-diroption is extraneous and has been removed. To handle this, remove any instances of--ignore-db-dirfrom your startup configuration. In addition, remove or move the named data directory subdirectories before upgrading to MySQL 8.0. (Alternatively, let the 8.0 server add those directories to the data dictionary as databases, then remove each of those databases usingDROP DATABASE.) -
If you intend to change the
lower_case_table_namessetting to 1 at upgrade time, ensure that schema and table names are lowercase before upgrading. Otherwise, a failure could occur due to a schema or table name lettercase mismatch. You can use the following queries to check for schema and table names containing uppercase characters:mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME != LOWER(TABLE_NAME) AND TABLE_TYPE = 'BASE TABLE'; mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME != LOWER(SCHEMA_NAME);As of MySQL 8.0.19, if
lower_case_table_names=1, table and schema names are checked by the upgrade process to ensure that all characters are lowercase. If table or schema names are found to contain uppercase characters, the upgrade process fails with an error.NoteChanging the
lower_case_table_namessetting at upgrade time is not recommended.
If upgrade to MySQL 8.0 fails due to any of the issues outlined above, the server reverts all changes to the data directory. In this case, remove all redo log files and restart the MySQL 5.7 server on the existing data directory to address the errors. The redo log files (ib_logfile*) reside in the MySQL data directory by default. After the errors are fixed, perform a slow shutdown (by setting innodb_fast_shutdown=0) before attempting the upgrade again.
-
A schema mismatch in a MySQL 5.7 instance between the
.frmfile of a table and theInnoDBdata dictionary can cause an upgrade to MySQL 8.0 to fail. Such mismatches may be due to.frmfile corruption. To address this issue, dump and restore affected tables before attempting the upgrade again. -
If problems occur, such as that the new mysqld server does not start, verify that you do not have an old
my.cnffile from your previous installation. You can check this with the--print-defaultsoption (for example, mysqld --print-defaults). If this command displays anything other than the program name, you have an activemy.cnffile that affects server or client operation. -
If, after an upgrade, you experience problems with compiled client programs, such as
Commands out of syncor unexpected core dumps, you probably have used old header or library files when compiling your programs. In this case, check the date for yourmysql.hfile andlibmysqlclient.alibrary to verify that they are from the new MySQL distribution. If not, recompile your programs with the new headers and libraries. Recompilation might also be necessary for programs compiled against the shared client library if the library major version number has changed (for example, fromlibmysqlclient.so.20tolibmysqlclient.so.21). -
If you have created a user-defined function (UDF) with a given name and upgrade MySQL to a version that implements a new built-in function with the same name, the UDF becomes inaccessible. To correct this, use
DROP FUNCTIONto drop the UDF, and then useCREATE FUNCTIONto re-create the UDF with a different nonconflicting name. The same is true if the new version of MySQL implements a built-in function with the same name as an existing stored function. See Section 9.2.5, “Function Name Parsing and Resolution”, for the rules describing how the server interprets references to different kinds of functions. -
If upgrade to MySQL 8.0 fails due to any of the issues outlined in Section 2.11.5, “Preparing Your Installation for Upgrade”, the server reverts all changes to the data directory. In this case, remove all redo log files and restart the MySQL 5.7 server on the existing data directory to address the errors. The redo log files (
ib_logfile*) reside in the MySQL data directory by default. After the errors are fixed, perform a slow shutdown (by settinginnodb_fast_shutdown=0) before attempting the upgrade again.
This section describes how to rebuild or repair tables or indexes, which may be necessitated by:
-
Changes to how MySQL handles data types or character sets. For example, an error in a collation might have been corrected, necessitating a table rebuild to update the indexes for character columns that use the collation.
-
Required table repairs or upgrades reported by
CHECK TABLE, mysqlcheck, or mysql_upgrade.
Methods for rebuilding a table include:
If you are rebuilding tables because a different version of MySQL will not handle them after a binary (in-place) upgrade or downgrade, you must use the dump-and-reload method. Dump the tables before upgrading or downgrading using your original version of MySQL. Then reload the tables after upgrading or downgrading.
If you use the dump-and-reload method of rebuilding tables only for the purpose of rebuilding indexes, you can perform the dump either before or after upgrading or downgrading. Reloading still must be done afterward.
If you need to rebuild an InnoDB table because a CHECK TABLE operation indicates that a table upgrade is required, use mysqldump to create a dump file and mysql to reload the file. If the CHECK TABLE operation indicates that there is a corruption or causes InnoDB to fail, refer to Section 15.21.2, “Forcing InnoDB Recovery” for information about using the innodb_force_recovery option to restart InnoDB. To understand the type of problem that CHECK TABLE may be encountering, refer to the InnoDB notes in Section 13.7.3.2, “CHECK TABLE Statement”.
To rebuild a table by dumping and reloading it, use mysqldump to create a dump file and mysql to reload the file:
mysqldumpdb_namet1 > dump.sql mysqldb_name< dump.sql
To rebuild all the tables in a single database, specify the database name without any following table name:
mysqldumpdb_name> dump.sql mysqldb_name< dump.sql
To rebuild all tables in all databases, use the --all-databases option:
mysqldump --all-databases > dump.sql mysql < dump.sql
To rebuild a table with ALTER TABLE, use a “null” alteration; that is, an ALTER TABLE statement that “changes” the table to use the storage engine that it already has. For example, if t1 is an InnoDB table, use this statement:
ALTER TABLE t1 ENGINE = InnoDB;
If you are not sure which storage engine to specify in the ALTER TABLE statement, use SHOW CREATE TABLE to display the table definition.
The REPAIR TABLE method is only applicable to MyISAM, ARCHIVE, and CSV tables.
You can use REPAIR TABLE if the table checking operation indicates that there is a corruption or that an upgrade is required. For example, to repair a MyISAM table, use this statement:
REPAIR TABLE t1;
mysqlcheck --repair provides command-line access to the REPAIR TABLE statement. This can be a more convenient means of repairing tables because you can use the --databases or --all-databases option to repair all tables in specific databases or all databases, respectively:
mysqlcheck --repair --databases db_name ...
mysqlcheck --repair --all-databases
In cases where you need to transfer databases between different architectures, you can use mysqldump to create a file containing SQL statements. You can then transfer the file to the other machine and feed it as input to the mysql client.
Use mysqldump --help to see what options are available.
If GTIDs are in use on the server where you create the dump (gtid_mode=ON), by default, mysqldump includes the contents of the gtid_executed set in the dump to transfer these to the new machine. The results of this can vary depending on the MySQL Server versions involved. Check the description for mysqldump's --set-gtid-purged option to find what happens with the versions you are using, and how to change the behavior if the outcome of the default behavior is not suitable for your situation.
The easiest (although not the fastest) way to move a database between two machines is to run the following commands on the machine on which the database is located:
mysqladmin -h 'other_hostname' createdb_namemysqldumpdb_name| mysql -h 'other_hostname'db_name
If you want to copy a database from a remote machine over a slow network, you can use these commands:
mysqladmin createdb_namemysqldump -h 'other_hostname' --compressdb_name| mysqldb_name
You can also store the dump in a file, transfer the file to the target machine, and then load the file into the database there. For example, you can dump a database to a compressed file on the source machine like this:
mysqldump --quickdb_name| gzip >db_name.gz
Transfer the file containing the database contents to the target machine and run these commands there:
mysqladmin createdb_namegunzip <db_name.gz | mysqldb_name
You can also use mysqldump and mysqlimport to transfer the database. For large tables, this is much faster than simply using mysqldump. In the following commands, DUMPDIR represents the full path name of the directory you use to store the output from mysqldump.
First, create the directory for the output files and dump the database:
mkdirDUMPDIRmysqldump --tab=DUMPDIRdb_name
Then transfer the files in the DUMPDIR directory to some corresponding directory on the target machine and load the files into MySQL there:
mysqladmin createdb_name# create database catDUMPDIR/*.sql | mysqldb_name# create tables in database mysqlimportdb_nameDUMPDIR/*.txt # load data into tables
Do not forget to copy the mysql database because that is where the grant tables are stored. You might have to run commands as the MySQL root user on the new machine until you have the mysql database in place.
After you import the mysql database on the new machine, execute mysqladmin flush-privileges so that the server reloads the grant table information.
浙公网安备 33010602011771号