Performing a MySQL Upgrade

Every time you update your version of MySQL it’s necessary to perform a mysql_upgrade. The reason that this is necessary is so that tables rows, and columns get updated and optimized. Additionally if you do not do a mysql_upgrade after a version upgrade, your backups will more than likely not work.

To be more precise (correcting the line above): mysql_upgrade does not optimize anything. It checks every table for incompatibilities with the new server version, repairs or upgrades the tables that need it, and updates the system tables in the mysql schema (privileges, help tables and so on) so they match the new release. Backups are not automatically broken if you skip it, but tools like mysqldump can fail or warn on system tables that are still in the old format, so running it is the right habit after every major version change.

** NOT RESPONSIBLE FOR DATA LOSS, HAVE A BACKUP, AND BE READY TO RESTORE!!! **

Prerequisites

  • The new MySQL (or MariaDB) packages are already installed and the server has been started on the new version. mysql_upgrade talks to the running server, it does not upgrade the binaries.
  • A fresh backup taken before the package upgrade, for example with mysqldump or mariadb-backup (see the backup guide linked below).
  • The MySQL root password, or another account with full privileges.

Steps

here’s what we need to do:

login and su to root

Root shell prompt on the MySQL master server

from here run the upgrade command

mysql_upgrade -u root -p
mysql_upgrade -u root -p typed at the root prompt

-u root connects as the MySQL root user and -p makes it prompt for that user’s password. It then runs a check on every database (it uses mysqlcheck --check-upgrade behind the scenes) and finishes by upgrading the system tables.

the results should look as shown:

Same screenshot: mysql_upgrade -u root -p, shown where the step describes the expected results

(The screenshot only repeats the command. A normal run prints one line per table ending in OK, followed by a message that the system tables were upgraded.)

if you run into issues, you may have to use the –force option

mysql_upgrade -u root -p --force

mysql_upgrade writes the version it upgraded to into a file called mysql_upgrade_info in the data directory (normally /var/lib/mysql). If that file says the upgrade was already done it refuses to run again; --force tells it to run anyway.

Restart the database service afterwards so the server starts cleanly with the updated system tables:

service mysqld restart

Verify

mysql -u root -p -e "SELECT VERSION();"
cat /var/lib/mysql/mysql_upgrade_info

The version from the query and the version in mysql_upgrade_info should match the release you just installed, and the MySQL error log should not show complaints about system tables.

Common errors

  • Can’t connect to local MySQL server through socket: the server is not running. Start it first; mysql_upgrade needs a live server.
  • Access denied for user ‘root’@’localhost’: wrong password, or the account uses socket authentication (common on MariaDB). On MariaDB run it as the Linux root user without -p.
  • This installation of MySQL is already upgraded: it has already been run for this version. Add --force only if you really need to run it again.
  • Tables reported as needing repair: check the output for the table names and repair them (or restore them from the backup) before putting the server back into production.

MySQL 8 and MariaDB on RHEL, AlmaLinux and Rocky 9/10

Since MySQL 8.0.16 the server does the upgrade work itself when it starts on a new version, and mysql_upgrade is deprecated and dropped from later releases. After a dnf upgrade you simply restart mysqld and watch the error log. MariaDB still uses the separate tool, now called mariadb-upgrade (mysql_upgrade remains as a compatibility name):

systemctl restart mariadb
mariadb-upgrade

For installing and backing up MariaDB on current AlmaLinux see Install MariaDB and MySQL on AlmaLinux 10 and MariaDB and MySQL backups with mysqldump and mariadb-backup.

That’s it! Your Database has been upgraded to the latest version

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Convert MySQL Slave to Master · Find Database Names Microsoft SQL Server · Create Windows Share Oracle Linux

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *