I installed ubuntu 16.04, after that when i try to install mysql it shows error as

$ sudo apt-get update
[sudo] password for mcerc: 
Reading package lists... Done
mcerc@mcerc-ThinkCentre-M72e:~$ sudo apt-get install mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package mysql
mcerc@mcerc-ThinkCentre-M72e:~$ sudo apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package mysql-server
mcerc@mcerc-ThinkCentre-M72e:~$ ^C

6 Answers 6


Whenever u install fresh Ubuntu , you need to update and upgrade the system to install from ubuntu repositories.

sudo apt-get update && sudo apt-get dist-upgrade

Now install anything

 sudo apt-get install mysql-server
  • 3
    You're geneous +1 Apr 25, 2019 at 4:53
  • @ViperTecPro haha. :)
    – minigeek
    May 1, 2019 at 16:57
  • Nope, this is the WRONG answer. OP (original poster) has already posted the output of sudo apt update. It went without any errors... This is the wrong answer. The correct answer is "All your repositories are disabled, open software properties gtk and enable all the repositories and run apt update and install MySQL again."
    – Error404
    Feb 13, 2022 at 13:01
  • First, goto Ubuntu Software and in the menu there will be the option Ubuntu Software. Select it.
  • There, you will Softwares and Updates. Select it. Check if all the official repositories (under the option Ubuntu Software) are checked. If not then check them.
  • Else use the following command for installing mysql-server sudo apt install mysql-server-5.7. This should work.

UPDATE: Ubuntu Software tab is moved to Software & Update, a separate application in Ubuntu 18.04

  • You can't very well go to Ubuntu Software via the command line...
    – chrips
    Nov 20, 2018 at 13:49

Your problem : mysql-server maybe was installed once and the settings in your machine might be saved somewhere . Remove it completely with .

Uninstall mysql-server first:

sudo apt-get remove --purge mysql-server 

install it again. Run this command:

sudo apt-get install mysql-server

This also help to fix broken packages, so if these commands above failed tried to fix packages first and then remove and install the mysql-server:

sudo apt-get -f install

Thank you for this. I had an issue installing openssh-server on my Ubuntu 16. I tried above solution and it installs openssh-server successfully. Here is what I tries:

sudo apt-get update && sudo apt-get dist-upgrade
sudo apt-get remove --purge openssh-server 
sudo apt-get install openssh-server 
sudo apt-get -f install

Hope this will help someone.

  • it is not related openssh-server its related mysql-server kindly post the relevant answer for the question
    – Kishore
    Nov 23, 2020 at 8:17

The other answers should work normally, but for me something was circularly misconfigured somehow and sudo apt purge mysql* -y just gave me

E: Unable to locate package mysql-apt-config_0.8.9-1_all.deb

but also sudo apt-get update && sudo apt-get dist-upgrade
just gave me

dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

So I thought if apt can't handle it on it's own, I'll bring on the big guy: dpkg

First I queried all packages containing mysql with

sudo dpkg-query -l | less | grep mysql

then I purged all of them one by one like

sudo dpkg --purge mysql-common
sudo dpkg --purge mysql-server-8.0
sudo dpkg --purge mysql-server-core-8.0

Then I ran all the commands suggested here + sudo apt autoremove, so after that I could reinstall it just like normal.

Hope this will help someone.


I had the same problem as you, and here is how I resolved it:

sudo apt-get update && sudo apt-get dist-upgrade

sudo apt-get install mysql-server

  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 24, 2023 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .