4

Using Kubuntu 17.04. I tried to install mariadb, which did not work, so now I am trying to revert back to mysql. However when I try to install mysql it is not working anymore either:

~# apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
mysql-server is already the newest version (5.7.19-0ubuntu0.17.04.1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies.
 mysql-server : Depends: mysql-server-5.7 but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

So then I tried the suggest --fix-broken:

~# apt-get --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  mysql-server-5.7
Suggested packages:
  tinyca
The following NEW packages will be installed
  mysql-server-5.7
0 to upgrade, 1 to newly install, 0 to remove and 0 not to upgrade.
5 not fully installed or removed.
Need to get 3,363 kB of archives.
After this operation, 50.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://gb.archive.ubuntu.com/ubuntu zesty-updates/main amd64 mysql-server-5.7 amd64 5.7.19-0ubuntu0.17.04.1 [3,363 kB]
Fetched 3,363 kB in 1s (3,049 kB/s)           
Preconfiguring packages ...
Selecting previously unselected package mysql-server-5.7.
(Reading database ... 304498 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
invoke-rc.d returned 5
There is a MySQL server running, but we failed in our attempts to stop it.
Stop it yourself and try again!
dpkg: error processing archive /var/cache/apt/archives/mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb (--unpack):
 subprocess new pre-installation script returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Am a little stuck now. Can anyone help me getting my system stable again?

Update: tried to run the suggested commands, but that did not solve the problem:

~$ sudo service mysql stop
Failed to stop mysql.service: Unit mysql.service not loaded.

~$ sudo apt -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  mysql-server-5.7
Suggested packages:
  tinyca
The following NEW packages will be installed
  mysql-server-5.7
0 to upgrade, 1 to newly install, 0 to remove and 5 not to upgrade.
5 not fully installed or removed.
Need to get 0 B/3,363 kB of archives.
After this operation, 50.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
Preconfiguring packages ...
(Reading database ... 304498 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
invoke-rc.d returned 5
There is a MySQL server running, but we failed in our attempts to stop it.
Stop it yourself and try again!
dpkg: error processing archive /var/cache/apt/archives/mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb (--unpack):
 subprocess new pre-installation script returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

~$ sudo pkill mysqld
~$ sudo killall mysqld
mysqld: no process found

~$ sudo apt -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  mysql-server-5.7
Suggested packages:
  tinyca
The following NEW packages will be installed
  mysql-server-5.7
0 to upgrade, 1 to newly install, 0 to remove and 5 not to upgrade.
5 not fully installed or removed.
Need to get 0 B/3,363 kB of archives.
After this operation, 50.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
Preconfiguring packages ...
(Reading database ... 304498 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
invoke-rc.d returned 5
There is a MySQL server running, but we failed in our attempts to stop it.
Stop it yourself and try again!
dpkg: error processing archive /var/cache/apt/archives/mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb (--unpack):
 subprocess new pre-installation script returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-5.7_5.7.19-0ubuntu0.17.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
5

I faced the same issue trying to upgrade from MySQL to MariaDB on Ubuntu 17.04 It was impossible to install MariaDB because the post-install script thought it failed to start the server (timeout error but the server was started). It was impossible to revert to MySQL because the install script thought it couldn't stop the server even if it was actually stopped.

Uninstalling with apt is difficult and overkill since it tries to uninstall every packages depending on MySQL client libraries.

Here is my solution to revert to MySQL then perform upgrading to MariaDB.

1) Detect all MariaDB and MySQL packages

apt search mariadb | grep "\[install"

and

apt search mysql | grep "\[install"

2) Force uninstall of all MariaDB and MySQL packages (server, client, libs) to clean the mess

sudo dpkg --force depends --purge <package> <package> ...

3) Clean remaining data in /etc and /var/lib/mysql

NB: I first tried to install both MariaDB or MySQL with my config and my data files but failed each time.

sudo rm -rf /var/lib/mysql* /etc/mysql

If you want to stick to MySQL and don't have a copy of your /var/lib/mysql in /var/lib/mysql-5.7 from the first MariaDB upgrade atempt, you shoud just move /var/lib/mysql /var/lib/mysql-5.7 instead of removing it.

4) Fix the system

sudo apt-get --fix-broken install
sudo apt autoremove
sudo reboot

5) Get MySQL data back

The --fix-broken install had reinstalled a clean MySQL (not a MariaDB since Ubuntu seems to like it that way).

sudo service mysql stop
mv /var/lib/mysql*5.7 /var/lib/mysql
sudo service mysql start

If you want to go to step 6 you should backup all your databases now.

6) Finally upgrade to MariaDB

If you already had backups, you can skip step 5.

sudo apt-get install mariadb-server

Yes, it was what I tried at first, but this time it works! You can recreate your database users and then restore your databases since MariaDB doesn't want to upgrade MySQL 5.7 bases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.