0

I am trying to install mysql server on my Ubuntu 22.04 LTS but couldnt do that it says unmet dependencies and i tried installing the required dependencies but it didnt work.

sudo apt install mysql-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies: mysql-common : Conflicts: mysql-server-8.0 but 8.0.29-0ubuntu0.22.04.2 is to be installed mysql-server-8.0 : Depends: mysql-client-8.0 (>= 8.0.29-0ubuntu0.22.04.2) but it is not installable Depends: mysql-server-core-8.0 (= 8.0.29-0ubuntu0.22.04.2) but it is not installable E: Unable to correct problems, you have held broken packages.

karel
  • 122,292
  • 133
  • 301
  • 332

4 Answers4

0

Use aptitude instead of apt-get. If you don't have aptitude on your machine yet, get it with:

sudo apt-get install aptitude

Then run:

sudo aptitude install mysql-server

In the prompt, you should not accept the first solution (enter n) to force reload of dependencies.

0

One of the most common reason why this happens is because you have some old MySQL or MariaDB packages installed on your system. MariaDB is a drop-in replacement for MySQL and both use the same library names and files (both in /var/lib/mysql and /etc/mysql/my.conf). Check this post: Why does Ubuntu prohibit installing both MySQL and MariaDB via apt? for more details. You can do some clean up and try to install the MySQL server again.

To check if this is your problem, run:

apt list --installed | grep mysql
apt list --installed | grep mariadb

Look for mysql-server, mysql-client, mariadb-server, mariadb-client and other similar packages.

If you want to install MySQL, you will have to uninstall these. You can remove them manually one by one or use apt with wildcard(*) like this:

sudo apt remove mysql*
sudo apt remove mariadb*
sudo apt autoremove

Install MySQL Server:

sudo apt install mysql-server
sotirov
  • 4,379
0

Try running the command

   sudo apt purge --remove *mysql*

It will remove the all mysql related packages and its related data directories and even logs

Next try installing it again

sudo apt install mysql-server-core-8.0 mysql-server-8.0
Sreedhar
  • 11
  • 2
-1

Overview

It seems that the problem comes from some partial initialization remaining in the filesystem from the first, failed installation. So the solution is basically to make sure to clear out everything that was added or modified during the failed install attempts.

I didn't have time to dive much deeper, so I don't know precisely which files are to blame, but if anyone can offer more insight, please comment below for future readers who need a more delicate solution.

I was able to resolve this issue on Ubuntu 22.04 as described below, using arief21's solution to a similar problem on 20.04, which itself was copied from here.

Purge Relevant Packages

  • Make sure MySQL is not running:
sudo systemctl stop mysql
  • Then purge all of the MySQL packages:
sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
  • Then delete all of the MySQL files:
sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql
  • Finally clean all packages that are not needed:
sudo apt autoremove
sudo apt autoclean
  • And it never hurts to do a reboot before moving on
sudo reboot

Now with any lingering configuration cruft culled, you should be able to run the install command again.

MySQL Apt Package Notes

I also read here that some people are experiencing problems with installation of the mysql-server on Jammy, recommending instead to install the specific mysql-server-8.0 and mysql-server-core-8.0 packages. Not 100% sure of the truth of this, as I didn't try the mysql-server metapackage again after a full purge.

sudo apt install mysql-server-core-8.0 mysql-server-8.0

Hope this helps!

aquilla
  • 159