How to upgrade to MySQL 8.0?

19,896

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.
Share:
19,896

Related videos on Youtube

fgtr
Author by

fgtr

Updated on September 18, 2022

Comments

  • fgtr
    fgtr over 1 year

    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

    • Admin
      Admin about 5 years
      wget https://repo.mysql.com//mysql-apt-config_0.8.12-1_all.deb doesn't add repository. It downloads the .deb package which is then installed using dpkg -i
    • Admin
      Admin about 5 years
      @Kulfy I followed this tutorial and nothing works at home tecmint.com/install-mysql-8-in-ubuntu
    • Admin
      Admin about 5 years
      What is the output of cat /etc/apt/sources.list.d/mysql.list?
    • Admin
      Admin about 5 years
      @Kulfy This file is empty. Here is the result of "apt-key list" pastebin.com/7e5UcBhs
  • fgtr
    fgtr about 5 years
    @Kufly Thank you, I will test it tonight. It's weird because I followed several blog posts and it does not work. Why it works for them? phoenixnap.com/kb/how-to-install-mysql-on-ubuntu-18-04 I restored my server, so I have to follow your answer ?
  • Kulfy
    Kulfy about 5 years
    @fgtr As I've stated in my answer as well as in comment, when I installed this package I was asked for choices 2-3 times. But since you have attached only 1 screenshot, it seems you made some wrong choices for which I'm not sure. You can try following my answer. It does exactly what that deb file does.
  • fgtr
    fgtr about 5 years
    Thank you, I updated the screenshots of my question
  • Kulfy
    Kulfy about 5 years
    @fgtr Everything looks ok but still I'm not sure why it created empty mysql.list. You can try my answer and let me know if it helps. I've tried this before posting and everything worked fine.
  • fgtr
    fgtr about 5 years
    Thanks it works, but if I update my database from version 5.7 to version 8.0 do I have to do mysql_upgrade? There are some explanations that I did not understand dev.mysql.com/doc/refman/8.0/en/mysql-upgrade.html
  • Kulfy
    Kulfy about 5 years
    @fgtr Not sure about that. I believe instructions are very much clear. You might like to run mysql_upgrade as they suggest. mysql_upgrade --protocol=tcp -P 3306 must be sufficient. 3306 is the default port number.
  • user9371654
    user9371654 about 5 years
    If I want to follow your solution, do I have to remove the old MySQL as the OP?
  • Kulfy
    Kulfy about 5 years
    @user9371654 Nope. Added the comment on your original post.