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
  • 114,770

3 Answers3

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.

  • mysql: Can't read dir of '/etc/mysql/mariadb.conf.d/' (OS errno 2 - No such file or directory) mysql: [ERROR] Stopped processing the 'includedir' directive in file /etc/mysql/my.cnf at line 29. mysql: [ERROR] Fatal error in defaults handling. Program aborted! – Ramu Singamsetty Jul 30 '22 at 06:43
  • I tried the same but it shows this – Ramu Singamsetty Jul 30 '22 at 06:43
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
  • 3,169
-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
  • 129
  • @aquila I followed your steps but still get: The following packages have unmet dependencies: mysql-common : Conflicts: mysql-server-8.0 but 8.0.30-0ubuntu0.22.04.1 is to be installed Conflicts: mysql-server-core-8.0 but 8.0.30-0ubuntu0.22.04.1 is to be installed mysql-server-8.0 : Depends: mysql-client-8.0 (>= 8.0.30-0ubuntu0.22.04.1) but it is not installable E: Unable to correct problems, you have held broken packages. – CodeConnoisseur Sep 03 '22 at 14:15
  • @CodeConnoisseur do you know if you actually have packages held at a specific version?

    apt-mark showhold will list any held packages.

    – aquilla Sep 12 '22 at 19:51
  • I had to actually purge all of mysql from my ubuntu installation then re-install from scratch. – CodeConnoisseur Sep 12 '22 at 21:08