mysql_upgrade

You are viewing an old version of this article. View the current version here.
MariaDB starting with 10.4.6

From MariaDB 10.4.6, mariadb-upgrade is a symlink to mysql_upgrade.

MariaDB starting with 10.5.2

From MariaDB 10.5.2, mysql_upgrade is the symlink, and mariadb-upgrade the binary name.

MariaDB starting with 10.2.42

Starting from mysql_upgrade / mariadb-upgrade 2.0, the user running the upgrade tool must have write access to datadir/mysql_upgrade_info, so that the tool can write the current MariaDB version into the file. mysql-upgrade was updated in MariaDB 10.2.42, MariaDB 10.3.33, MariaDB 10.4.23, MariaDB 10.5.14, MariaDB 10.6.6, MariaDB 10.7.2 and newer.

mariadb-upgrade/mysql_upgrade is a tool that checks and updates your tables to the latest version.

You should run mariadb-upgrade/mysql_upgrade after upgrading from one major MySQL/MariaDB release to another, such as from MySQL 5.0 to MariaDB 10.4 or MariaDB 10.4 to MariaDB 10.5. You also have to use mysql_upgrade after a direct "horizontal" migration, for example from MySQL 5.5.40 to MariaDB 5.5.40. It's also safe to run mariadb-upgrade/mysql_upgrade for minor upgrades, as if there are no incompatibilities nothing is changed.

It needs to be run as a user with write access to the data directory.

mariadb-upgrade/mysql_upgrade is run after starting the new MariaDB server. Running it before you shut down the old version will not hurt anything and will allow you to make sure it works and figure out authentication for it ahead of time.

It is recommended to make a backup of all the databases before running mariadb-upgrade/mysql_upgrade.

In most cases, mariadb-upgrade/mysql_upgrade should just take a few seconds. The main work of mariadb-upgrade/mysql_upgrade is to:

  • Update the system tables in the mysql database to the latest version (normally just add new fields to a few tables).
  • Check that all tables are up to date (runs CHECK TABLE table_name FOR UPGRADE). For tables that are not up to date, runs ALTER TABLE table_name FORCE on the table to update it. A table is not up to date if:
    • The table uses an index for which there has been a collation change (rare)
    • A format change in the storage engine requires an update (very rare)

Using mariadb-upgrade/mysql_upgrade

mysql_upgrade [--force] [--user=# --password=# 
  --host=hostname --port=# --socket=#
  --protocol=tcp|socket|pipe|memory 
  --verbose] [OTHER_OPTIONS]

mariadb-upgrade/mysql_upgrade is mainly a framework to call mysqlcheck. mysql_upgrade works by doing the following operations:

# Find out path to datadir
echo "show show variables like 'datadir'" | mysql
mysqlcheck --no-defaults --check-upgrade --auto-repair --databases mysql
mysql_fix_privilege_tables
mysqlcheck --no-defaults --all-databases --fix-db-names --fix-table-names
mysqlcheck --no-defaults --check-upgrade --all-databases --auto-repair

The connect options given to mariadb-upgrade/mysql_upgrade are passed along to mysqlcheck and mysql.

The mysql_fix_privilege_tables script is not actually called; it's included as part of mysql_upgrade

If you have a problem with mariadb-upgrade/mysql_upgrade try run it in very verbose mode:

mysql_upgrade --verbose --verbose other-options

mariadb-upgrade/mysql_upgrade also saves the MariaDB version number in a file named mysql_upgrade_info in the data directory. This is used to quickly check whether all tables have been checked for this release so that table-checking can be skipped. For this reason, mysql_upgrade needs to be run as a user with write access to the data directory. To ignore this file and perform the check regardless, use the --force option.

Options

mariadb-upgrade/mysql_upgrade supports the following options:

OptionDescriptionVersion
-?, --helpDisplay this help message and exit.
--basedir=pathOld option accepted for backward compatibility but ignored.
--character-sets-dir=pathOld option accepted for backward compatibility but ignored.
check-if-upgrade-is-neededDo a quick check if upgrade is needed. Returns 0 if yes, 1 if no.2.0
--compress=nameOld option accepted for backward compatibility but ignored.
--datadir=nameOld option accepted for backward compatibility but ignored.
-# [name], --debug[=name]For debug builds, output debug log.
--debug-checkCheck memory and open file usage at exit.
-T, --debug-infoPrint some debug info at exit.
--default-character-set=nameOld option accepted for backward compatibility but ignored.
-f, --forceForce execution of mysqlcheck even if mysql_upgrade has already been executed for the current version of MariaDB. Ignores mysql_upgrade_info.
-h, --host=nameConnect to MariaDB on the given host.
-p, --password[=name]Password to use when connecting to server. If password is not given, it's solicited on the command line (which should be considered insecure). You can use an option file to avoid giving the password on the command line.
-P, --port=namePort number to use for connection or 0 for default to, in order of preference, my.cnf, the MYSQL_TCP_PORT environment variable, /etc/services, built-in default (3306).
--protocol=nameThe protocol to use for connection (tcp, socket, pipe, memory).
--silentPrint less information.
-S, --socket=nameFor connections to localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.
--sslEnables TLS. TLS is also enabled even without setting this option when certain other TLS options are set. Starting with MariaDB 10.2, the --ssl option will not enable verifying the server certificate by default. In order to verify the server certificate, the user must specify the --ssl-verify-server-cert option.
--ssl-ca=nameDefines a path to a PEM file that should contain one or more X509 certificates for trusted Certificate Authorities (CAs) to use for TLS. This option requires that you use the absolute path, not a relative path. See Secure Connections Overview: Certificate Authorities (CAs) for more information. This option implies the --ssl option.
--ssl-capath=nameDefines a path to a directory that contains one or more PEM files that should each contain one X509 certificate for a trusted Certificate Authority (CA) to use for TLS. This option requires that you use the absolute path, not a relative path. The directory specified by this option needs to be run through the openssl rehash command. See Secure Connections Overview: Certificate Authorities (CAs) for more information. This option is only supported if the client was built with OpenSSL or yaSSL. If the client was built with GnuTLS or Schannel, then this option is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms. This option implies the --ssl option.
--ssl-cert=nameDefines a path to the X509 certificate file to use for TLS. This option requires that you use the absolute path, not a relative path. This option implies the --ssl option.
--ssl-cipher=nameList of permitted ciphers or cipher suites to use for TLS. This option implies the --ssl option.
--ssl-crl=nameDefines a path to a PEM file that should contain one or more revoked X509 certificates to use for TLS. This option requires that you use the absolute path, not a relative path. See Secure Connections Overview: Certificate Revocation Lists (CRLs) for more information. This option is only supported if the client was built with OpenSSL or Schannel. If the client was built with yaSSL or GnuTLS, then this option is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms.
--ssl-crlpath=nameDefines a path to a directory that contains one or more PEM files that should each contain one revoked X509 certificate to use for TLS. This option requires that you use the absolute path, not a relative path. The directory specified by this option needs to be run through the openssl rehash command. See Secure Connections Overview: Certificate Revocation Lists (CRLs) for more information. This option is only supported if the client was built with OpenSSL. If the client was built with yaSSL, GnuTLS, or Schannel, then this option is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms.
--ssl-key=nameDefines a path to a private key file to use for TLS. This option requires that you use the absolute path, not a relative path. This option implies the --ssl option.
--ssl-verify-server-certEnables server certificate verification. This option is disabled by default.
-t, --tmpdir=nameDirectory for temporary files.
-s, --upgrade-system-tablesOnly upgrade the system tables in the mysql database. Tables in other databases are not checked or touched.
-u, --user=nameUser for login if not current user.
-v, --verboseDisplay more output about the process, using it twice will print connection arguments; using it 3 times will print out all CHECK, RENAME and ALTER TABLE commands used during the check phase; using it 4 times will also write out all mysqlcheck commands used.
-V, --versionOutput version information and exit.
-k, --version-checkRun this program only if its 'server version' matches the version of the server to which it's connecting check. Note: the 'server version' of the program is the version of the MariaDB server with which it was built/distributed. (Defaults to on; use --skip-version-check to disable.)
--write-binlogAll commands including those run by mysqlcheck are written to the binary log. Disabled by default. Before MariaDB 10.0.6 and MariaDB 5.5.34, this was enabled by default, and --skip-write-binlog should be used when commands should not be sent to replication slaves.

mariadb-upgrade/mysql_upgrade 2.0

mariadb-upgrate/mysql_upgrade 2.0 was introduced in MariaDB 10.2.42, MariaDB 10.3.33, MariaDB 10.4.23, MariaDB 10.5.14, MariaDB 10.6.6, MariaDB 10.7.2.

Previously the tool first ran the upgrade process and then created the datadir/mysql_upgrade_info file. If the file could not be created because of permissions (mysql_upgrade did not have rights to create the file), mariadb-upgrade/mysql_upgrade gave an error, but this was often ignored. One effect of not being able to create the mysql_upgrade_info file was that every new mysql_upgrade run would have to do a full upgrade check, which can take a while if there are a lot of tables.

mariadb-upgrade/mysql_upgrade 2.0 fixes the following issues:

  • The datadir/mysql_upgrade_info is now created at the start of the upgrade process and locked. This ensures that two mariadb-upgrade/mysql_upgrade processes cannot be run in parallel, which can cause deadlocks (MDEV-27068). One side-effect of this is that mariadb-upgrade/mysql_upgrade has to have write access to datadir, which means it has to be run as as the user that installed MariaDB, normally 'mysql' or 'root' .
  • One can use mariadb-upgrade/mysql_upgrade --force --force to force the upgrade to be run, even if there was no version change or if one doesn't have write access to datadir. Note that if this option is used, the next mariadb-upgrade/mysql_upgrade run will assume that there is a major version change and the upgrade must be done (again).
  • The upgrade will only be done if there is a major server version change (10.4.X -> 10.5.X). This will avoid unnecessary upgrades.
  • New option added: --check-if-upgrade-is-needed. If this is used, mariadb-upgrade/mysql_upgrade will return 0 if there has been a major version change and one should run mariadb-upgrade/mysql_upgrade. If not upgrade is need, 1 will be returned.
  • --verbose writes more information, including from which version to which version the upgrade will be done.
  • Better messages when there is no need to run mariadb-upgrade/mysql_upgrade.

Option Files

In addition to reading options from the command-line, mariadb-upgrade/mysql_upgrade can also read options from option files. If an unknown option is provided to mariadb-upgrade/mysql_upgrade in an option file, then it is ignored.

The following options relate to how MariaDB command-line tools handles option files. They must be given as the first argument on the command-line:

OptionDescription
--print-defaultsPrint the program argument list and exit.
--no-defaultsDon't read default options from any option file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# In addition to the default option groups, also read option groups with this suffix.

In MariaDB 10.2 and later, mariadb-upgrade/mysql_upgrade is linked with MariaDB Connector/C. However, MariaDB Connector/C does not yet handle the parsing of option files for this client. That is still performed by the server option file parsing code. See MDEV-19035 for more information.

Option Groups

mariadb-upgrade/mysql_upgrade reads options from the following option groups from option files:

GroupDescription
[mysql_upgrade] Options read by mysql_upgrade, which includes both MariaDB Server and MySQL Server.
[mariadb-upgrade]Options read by mysql_upgrade. Available starting with MariaDB 10.4.6.
[client] Options read by all MariaDB and MySQL client programs, which includes both MariaDB and MySQL clients. For example, mysqldump.
[client-server]Options read by all MariaDB client programs and the MariaDB Server. This is useful for options like socket and port, which is common between the server and the clients.
[client-mariadb]Options read by all MariaDB client programs.

Differences Between mysql_upgrade in MariaDB and MySQL

This is as of MariaDB 5.1.50:

  • MariaDB will convert long table names properly.
  • MariaDB will convert InnoDB tables (no need to do a dump/restore or ALTER TABLE).
  • MariaDB will convert old archive tables to the new 5.1 format.
  • "mysql_upgrade --verbose" will run "mysqlcheck --verbose" so that you get more information of what is happening. Running with 3 times --verbose will in MariaDB 10.0 print out all CHECK, RENAME and ALTER TABLE commands executed.
  • The mysql.event table is upgraded live; no need to restart the server to use events if the event table has changed (MariaDB 10.0.22 and MariaDB 10.1.9).
  • More descriptive output.

Speeding Up mariadb-upgrade/mysql_upgrade

- If you are sure that all your tables are up to date with the current version, then you can run mysql_upgrade ---upgrade-system-tables, which will only fix your system tables in the mysql database to be compatible with the latest version.

The main reason to run mariadb-upgrade/mysql_upgrade on all your tables is to allow it to check that:

  • There has not been any change in table formats between versions.
  • If some of the tables are using an index for which we have changed sort order.

If you are 100% sure this applies to you, you can just run mariadb-upgrade/mysql_upgrade with the ---upgrade-system-tables option.

Symptoms of Not Having Run mariadb-upgrade/mysql_upgrade When It Was Needed

  • Errors in the error log that some system tables don't have all needed columns.
  • Updates or searches may not find the record they are attempting to update or search for.
  • CHECKSUM TABLE may report the wrong checksum for MyISAM or Aria tables.
  • The error message "Cannot load from mysql.proc. The table is probably corrupted."

To fix issues like this, run mariadb-upgrade/mysql_upgrade, mysqlcheck, CHECK TABLE and if needed REPAIR TABLE on the wrong table.

Other Uses

  • mariadb-upgrade/mysql_upgrade will re-create any missing tables in the mysql database. It will not touch any data in existing tables.

See Also

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.