10

I am trying to install mysql-server on ubuntu 22.04 LTS but I am getting the following dpkg error message. How can I fix this issue ?

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
 mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-ore-8.0
Suggested packages:
 mailx tinyca
The following NEW packages will be installed:
 mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 6 newly installed, 0 to remove and 3 not upgraded.
Need to get 0 B/21.1 MB of archives.
After this operation, 182 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 201995 files and directories currently installed.)
Preparing to unpack .../mysql-common_1%3a10.5.15+maria~focal_all.deb ...
Unpacking mysql-common (1:10.5.15+maria~focal) ...
Selecting previously unselected package mysql-client-core-8.0.
Preparing to unpack .../mysql-client-core-8.0_8.0.28-0ubuntu4_amd64.deb ...
Unpacking mysql-client-core-8.0 (8.0.28-0ubuntu4) ...
Selecting previously unselected package mysql-client-8.0.
Preparing to unpack .../mysql-client-8.0_8.0.28-0ubuntu4_amd64.deb ...
Unpacking mysql-client-8.0 (8.0.28-0ubuntu4) ...
Selecting previously unselected package mysql-server-core-8.0.
Preparing to unpack .../mysql-server-core-8.0_8.0.28-0ubuntu4_amd64.deb ...
Unpacking mysql-server-core-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-common (1:10.5.15+maria~focal) ...
Selecting previously unselected package mysql-server-8.0.
(Reading database ... 202191 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.28-0ubuntu4_amd64.deb ...
Unpacking mysql-server-8.0 (8.0.28-0ubuntu4) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_8.0.28-0ubuntu4_all.deb ...
Unpacking mysql-server (8.0.28-0ubuntu4) ...
Setting up mysql-client-core-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-server-core-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-client-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-server-8.0 (8.0.28-0ubuntu4) ...
/var/lib/dpkg/info/mysql-server-8.0.postinst: line 194: /usr/share/mysql- 
common/configure-symlinks: No such file or directory
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 127
No apport report written because the error message indicates its a followup error from a previous failure.
dpkg: dependency problems prevent configuration of mysql-server:

mysql-server depends on mysql-server-8.0; however: Package mysql-server-8.0 is not configured yet.

dpkg: error processing package mysql-server (--configure): dependency problems - leaving unconfigured Processing triggers for man-db (2.10.2-1) ... Errors were encountered while processing: mysql-server-8.0 mysql-server E: Sub-process /usr/bin/dpkg returned an error code (1)

Although running the command mysqld -V command produce the following output -

/usr/sbin/mysqld Ver 8.0.28-0ubuntu4 for Linux on x86_64 ((Ubuntu))

Executing the command sudo service mysql start produces the following error code -

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.

abhijit
  • 163

3 Answers3

13

Reposting my answer to a similar question here. I was able to resolve this issue on Ubuntu 22.04 using arief21's solution to a similar problem on 20.04, which itself was copied from here.

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.

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
  • 1
    Good answer. One of the most common reasons for repeated failures to install is detritus left over from earlier attempts. – user535733 Jun 29 '22 at 20:49
  • Well, This answer helped, I had to add one step, which was systemctl stop exim4 and systemctl disable exim4. It took me ages to get ride of a sick myql-server installation. – PouJa Feb 28 '24 at 00:16
  • Also check for any broken service link (/etc/systemd/system/mysql.service)

  • Remove any MariaDB stuff (sudo dpkg --get-selections | grep maria)

  • My experience may help here

  • – Kesavan Muthuvel Mar 03 '24 at 04:14