How to upgrade MySQL 5.7 to 8.0 on Ubuntu - Rocketeers

 On this page

 Knowledge
---------

How to upgrade MySQL 5.7 to 8.0 on Ubuntu
=========================================

### [\#Databases](http://rocketee.rs/index.php/databases)

Learn how to safely upgrade your database server from MySQL 5.7 to MySQL 8.0 on Ubuntu.

 Published by Mark van Eijk on January 12, 2023 · 1 minute read

1. [Backup existing databases (don't skip)](#content-backup-existing-databases-dont-skip)
2. [Remove current MySQL version](#content-remove-current-mysql-version)
3. [Install essential packages and add apt key](#content-install-essential-packages-and-add-apt-key)
4. [Add MySQL 8.0 repository source](#content-add-mysql-80-repository-source)
5. [Update apt repositories &amp; install MySQL 8.0](#content-update-apt-repositories--install-mysql-80)
6. [Check if MySQL 8.0 is installed](#content-check-if-mysql-80-is-installed)
7. [Help! MySQL doesn't start anymore](#content-help-mysql-doesnt-start-anymore)

### [\#](#content-backup-existing-databases-dont-skip "Permalink")Backup existing databases (don't skip)

Don't skip this part, it can save you a lot of trouble when something goes wrong!

[Backup the databases in separate files](/backup-mysql-databases-separate-files) or choose to [backup your databases in a single file](/backup-mysql-databases-single-file). Possibly the latter is easier when needing to import the backup and importing it all at once.

### [\#](#content-remove-current-mysql-version "Permalink")Remove current MySQL version

 ```
sudo apt purge mysql-*

```

### [\#](#content-install-essential-packages-and-add-apt-key "Permalink")Install essential packages and add apt key

 ```
sudo apt install -y dirmngr # essential package for adding apt key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29

```

### [\#](#content-add-mysql-80-repository-source "Permalink")Add MySQL 8.0 repository source

 ```
echo "deb http://repo.mysql.com/apt/ubuntu $(lsb_release -sc) mysql-8.0" | sudo tee /etc/apt/sources.list.d/mysql-8.0.list

```

### [\#](#content-update-apt-repositories--install-mysql-80 "Permalink")Update apt repositories &amp; install MySQL 8.0

 ```
sudo apt-get update
sudo apt-get install -y mysql-server mysql-client

```

### [\#](#content-check-if-mysql-80-is-installed "Permalink")Check if MySQL 8.0 is installed

When everything goes well, you're done. MySQL version 8.0 is installed. You can verify this by checking the status of the MySQL daemon and the MySQL version:

 ```
sudo service mysql status

```

This should output that MySQL is `active (running)`. To make sure you're on the new version, check the MySQL version:

 ```
sudo mysql --version

```

Should show something like:

 ```
mysql  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)

```

### [\#](#content-help-mysql-doesnt-start-anymore "Permalink")Help! MySQL doesn't start anymore

Check the error logs of MySQL to find the cause, most of the times it provides a clear message and it's probably because of some deprecated configuration inside in one of the `/etc/mysql` config files.

An example of an error message I have got in the past. Removing `NO_AUTO_CREATE_USER` from the `sql_mode` fixed the issue:

 ```
2023-01-12T09:21:12.834467Z 0 [ERROR] [MY-000077] [Server] /usr/sbin/mysqld: Error while setting value 'NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.

```

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### Related articles

[Stream MySQL backup directly to S3 bucket](http://rocketee.rs/index.php/stream-mysql-backup-s3-bucket)
-------------------------------------------------------------------------------------------------------

Learn how to safely upgrade your database server from MySQL 5.7 to MySQL 8.0 on Ubuntu.

[Read more →](http://rocketee.rs/index.php/stream-mysql-backup-s3-bucket)

[Export MySQL database using command line](http://rocketee.rs/index.php/export-database-mysql-command-line)
-----------------------------------------------------------------------------------------------------------

Learn how to safely upgrade your database server from MySQL 5.7 to MySQL 8.0 on Ubuntu.

[Read more →](http://rocketee.rs/index.php/export-database-mysql-command-line)
