What is mysql_upgrade?
If your server runs MySQL databases, then the mysql_upgrade command is one you’ll want to familiarize yourself with. Available only in Unix, mysql_upgrade is a command that checks all tables in all databases for incompatibilities with your current version of the MySQL Server.
After checking your databases, if a table is found to have possible incompatibilities, it is investigated in detail. If any problems are found, the table is repaired automatically.
Once all tables have been checked and repaired, they are marked with the current MySQL version number. This ensures that the next time you run the mysql_upgrade command with the same version of the server, it can determine whether there is any need to check or repair these tables again.
Another feature of mysql_upgrade is that it saves the MySQL version number into a file named mysql_upgrade.info. Contained within the data directory, this file is used to quickly review if all tables are current for this release, allowing future table-checking to be skipped.
Lastly, mysql_upgrade also upgrades the system tables. This allows users to take advantage of new privileges or capabilities that might have been added in new versions of MySQL.
For these reasons, mysql_upgrade should be executed each time you upgrade the MySQL Server to ensure that your tables remain up-to-date and compatible.
How to Use mysq_upgrade
To use mysql_upgrade, you’ll first need to make sure that your server is up and running. Then, from within the terminal, enter the following command:
The way mysql_upgrade works, is by automatically executing the following commands:
mysqlcheck --check-upgrade --all-databases --auto-repair