The latest version of MySQL server currently is 8.03. To upgrade MySQL server from a previous version we need to ensure that we are upgrading from the last stable release. For example from version 5.7 to 8.0. To upgrade from 5.6 to 8.0 we need to first upgrade from 5.6 to 5.7 and then from 5.7 to 8.0. Upgrading directly from 5.6 to 8.0, will result in errors related to incompatible sql or log file formats.
To install the MySQL apt repository we need to first download the repository package from: http://dev.mysql.com/downloads/repo/apt/. Next we need to install the repository package using the command: sudo dpkg -i mysql-apt-config_w.x.y-z_all.deb. During the installation of the package, we will be asked to choose the version of MySQL server and other tools. After the repository package has been installed we can install the MySQL server using the commands: apt-get update followed by apt-get install mysql-server. This will install the version of the MySQL server that we had selected during the repository package installation.
To change the version of MySQL server that we have installed, we need to issue the command: sudo dpkg-reconfigure mysql-apt-config. The version that we select here will be installed when we install the package from apt
Next we need to remove the MySQL server using the command: apt-get remove mysql-server. This command will remove the MySQL server binaries from the system. To remove the MySQL data we need to substitute remove with purge in the previous command.
After that we need to choose the new version of MySQL server from the MySQl apt configuration tool. We can access the tool with the command: sudo dpkg-reconfigure mysql-apt-config.
Next we need to install the new version of the MySQL server with the command: apt-get install mysql-server. During installation we will be prompted for the root password for the MySQL server.
If we had used the purge option while removing the MySQL server, then we will need to import the data back to the MySQL server. We can do this with the command: mysql -u root -p < database_file.sql
After the installation has completed we need to upgrade the server using the command: mysql_upgrade -u root -p. This will upgrade the table formats to the version support by the new MySQL server.