mysql_upgrade is a tool that checks and updates your tables to the latest version.

You should run mysql_upgrade after upgrading from one major MySQL/MariaDB release to another, such as from MySQL 5.0 to MariaDB 10.1 or MariaDB 10.0 to MariaDB 10.1. You also have to use mysql_upgrade after a direct "horizontal" migration from MySQL 5.5.40 to MariaDB 5.5.40. It's also safe to run mysql_upgrade for minor upgrades, as if there are no incompatibles between versions it changes nothing.

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.

On Windows Server 2008 or newer, mysql_upgrade needs to be run with administrator privileges.

It is recommended to make a backup of all the databases before running mysql_upgrade.

In most cases, mysql_upgrade should just take a few seconds. The main work of 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 mysql_upgrade

mysql_upgrade [--force] [--user=# --password 
  --host=hostname --port=# --socket=#
  --verbose] OTHER_OPTIONS]

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
mysqlcheck --no-defaults --all-databases --fix-db-names --fix-table-names --write-binlog
mysqlcheck --no-defaults --check-upgrade --all-databases --auto-repair --write-binlog

The connect options given to 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 mysql_upgrade, try run it in very verbose mode:

mysql_upgrade --verbose --verbose other-options


mysql_upgrade supports the following options:

-?, --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.
--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.
-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.
--sslEnable TLS for connection (automatically enabled with other flags).
--ssl-ca=nameCA file in PEM format (check OpenSSL docs, implies --ssl).
--ssl-capath=nameCA directory (check OpenSSL docs, implies --ssl).
--ssl-cert=nameX509 cert in PEM format (implies --ssl).
--ssl-cipher=nameSSL cipher to use (implies --ssl).
--ssl-key=nameX509 key in PEM format (implies --ssl).
--ssl-crl=nameCertificate revocation list (implies --ssl).
--ssl-crlpath=nameCertificate revocation list path (implies --ssl).
--ssl-verify-server-certVerify server's "Common Name" in its cert against hostname used when connecting. 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 (added in MariaDB 10.0.14) 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.

Option Files

In addition to reading options from the command-line, mysql_upgrade can also read options from option files. If an unknown option is provided to 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:

--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, 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

mysql_upgrade reads options from the following option groups from option files:

[mysql_upgrade] Options read by mysql_upgrade, which includes both MariaDB Server and MySQL Server.
[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 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 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 mysql_upgrade with the ---upgrade-system-tables option.

Symptoms of Not Having Run mysql_upgrade When It Was Needed

  • Errors in the error log that some system tables doesn't have all needed columns.
  • Updates or searches on may not find the record.
  • CHECKSUM TABLE may report the wrong checksum for MyISAM or Aria tables.

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

Other Uses

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

See Also


Comments loading...