How to upgrade to MySQL 8.0?

I have a Drupal site 8.6.10 on an Ubuntu server 18.04 with MySQL 5.7.25

I want to update MySQL to version 8.0

Here are the steps I followed :

  1. I backed up my database.

  2. I uninstalled MySQL from my server with the commands :

    $ sudo systemctl stop mysql
    $ sudo apt remove mysql-*
    $ sudo apt purge mysql-*
    $ sudo apt autoremove
    $ sudo dpkg -l | grep mysql | grep ii
    
  3. I added the repository with the command :

    $ wget https://repo.mysql.com//mysql-apt-config_0.8.12-1_all.deb
    
  4. I installed the package with the command :

    $ sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
    

enter image description here

enter image description here

enter image description here

enter image description here

My problem :

  1. I install MySQL with the command :

    $ sudo apt update
    $ sudo apt install mysql-server
    

When I do step 5, it installs MySQL 5.7 why does not it install version 8 ?

enter image description here


Basically mysql-apt-config_0.8.12-1_all.deb is a package which adds MySQL's repository and key. It seems while installing this package you made wrong choices somewhere. You can do what that deb package do manually.

  • First of all create a new text file with sudo privileges:

    sudo nano /etc/apt/sources.list.d/mysql.list
    
  • Add these lines:

    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config
    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-8.0
    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools
    #deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools-preview
    deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-8.0
    

    You can comment/uncomment the repository according to the packages required. Save and exit using Ctrl+X followed by Y.

  • If you're using some other version of Ubuntu, you should replace bionic with the codename of your currently installed Ubuntu system using sed.

    sudo sed -i 's/bionic/'$(lsb_release -sc)'/' /etc/apt/sources.list.d/mysql.list
    

    Then run

    sudo apt update
    
  • You'll get an error, like

    Err:1 http://repo.mysql.com/apt/ubuntu bionic InRelease                        
      The following signatures couldn't be verified because the public key is not available: NO_PUBKEY <some key value>
    
  • Add this key using

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <key value>
    
  • Update and install MySQL

    sudo apt update
    sudo apt install mysql-server
    

Notes:

  1. Ubuntu 19.10 has MySQL 8.0 in its official repositories, therefore, there's no need to add the above sources unless latest updates are required.
  2. If the above method is followed and still APT installs MySQL v5.7, it may happen that MySQL has taken down the repository information for that release even before that release reaches the end of public support. See my other answer on Can't install MySQL 8 on Ubuntu 19.04 for details.