mariadb 失败后安装 mysql-server

mariadb 失败后安装 mysql-server

使用 Kubuntu 17.04。我尝试安装 mariadb,但没有成功,所以现在我尝试恢复到 mysql。但是当我尝试安装 mysql 时,它也不起作用了:

~# 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).

因此我尝试了建议--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)

现在有点卡住了。有人能帮我让我的系统再次稳定下来吗?

更新:尝试运行建议的命令,但并未解决问题:

~$ 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)

答案1

我在 Ubuntu 17.04 上尝试从 MySQL 升级到 MariaDB 时遇到了同样的问题,无法安装 MariaDB,因为安装后脚本认为它无法启动服务器(超时错误,但服务器开始了)。无法恢复到 MySQL,因为安装脚本认为它无法停止服务器即使它真的停止了

使用 apt 卸载很困难并且有点过度,因为它会尝试卸载每个依赖于 MySQL 客户端库的软件包。

这是我的解决方案,先恢复到 MySQL,然后升级到 MariaDB。

1)检测所有 MariaDB 和 MySQL 包

apt search mariadb | grep "\[install"

apt search mysql | grep "\[install"

2)强制卸载所有 MariaDB 和 MySQL 软件包(服务器、客户端、库)以清理混乱

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

3)清理/etc和/var/lib/mysql中的剩余数据

注意:我首先尝试使用我的配置和数据文件安装 MariaDB 或 MySQL,但每次都失败。

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

如果您想坚持使用 MySQL,并且在第一次尝试升级 MariaDB 时没有 /var/lib/mysql-5.7 中的 /var/lib/mysql 副本,那么您应该移动 /var/lib/mysql /var/lib/mysql-5.7 而不是删除它。

4)修复系统

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

5)恢复 MySQL 数据

--fix-broken 安装已重新安装一个干净的 MySQL(而不是 MariaDB,因为 Ubuntu 似乎喜欢这样)。

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

如果你想进入第 6 步,你应该立即备份所有数据库

6)最后升级到 MariaDB

如果您已有备份,则可以跳过步骤 5。

sudo apt-get install mariadb-server

是的,这是我第一次尝试的,但这次有用!您可以重新创建数据库用户,然后恢复数据库,因为 MariaDB 不想升级 MySQL 5.7 基础。

答案2

就我而言,我很快就运行了 NextCloud。在安装 MariaDB 之前,我必须停止它。命令和错误的顺序如下:

$ sudo apt --fix-broken install
...
Failed to stop mariadb.service: Unit mariadb.service not loaded.
...
$ sudo snap stop nextcloud
$ sudo apt --fix-broken install

成功!

相关内容