更新 Ubuntu 后无法更新或删除 MySQL

更新 Ubuntu 后无法更新或删除 MySQL

两天前,我将服务器更新为 Xenial 版本,但不知何故,它完全破坏了我的 MySQL 配置。因此,我尝试更新它、删除它,但由于没有奏效,我尝试了在线找到的许多方法……但都没有奏效,我仍然被这个 MySQL 安装问题困扰。所以我想是时候寻求帮助了……

以下信息可能有助于识别问题:

sudo apt-get 安装 mysql 服务器 mysql 客户端

Reading package lists... Done
Building dependency tree       
Reading state information... Done
mysql-client is already the newest version (5.7.21-0ubuntu0.16.04.1).
mysql-server is already the newest version (5.7.21-0ubuntu0.16.04.1).
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Setting up mysql-server-5.7 (5.7.21-0ubuntu0.16.04.1) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo apt-get purge mysql*

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'mysqltcl' for glob 'mysql*'
Note, selecting 'mysql-mmm-agent' for glob 'mysql*'
Note, selecting 'mysql-workbench' for glob 'mysql*'
Note, selecting 'mysql-client-5.1' for glob 'mysql*'
Note, selecting 'mysql-client-5.5' for glob 'mysql*'
Note, selecting 'mysql-client-5.6' for glob 'mysql*'
Note, selecting 'mysql-client-5.7' for glob 'mysql*'
Note, selecting 'mysql-mmm-tools' for glob 'mysql*'
Note, selecting 'mysql-common-5.6' for glob 'mysql*'
Note, selecting 'mysql-server-5.0' for glob 'mysql*'
Note, selecting 'mysql-server-5.1' for glob 'mysql*'
Note, selecting 'mysql-server-5.5' for glob 'mysql*'
Note, selecting 'mysql-server-5.6' for glob 'mysql*'
Note, selecting 'mysql-server-5.7' for glob 'mysql*'
Note, selecting 'mysql-utilities' for glob 'mysql*'
Note, selecting 'mysql-testsuite' for glob 'mysql*'
Note, selecting 'mysql-mmm-common' for glob 'mysql*'
Note, selecting 'mysql-server' for glob 'mysql*'
Note, selecting 'mysql-client' for glob 'mysql*'
Note, selecting 'mysql-sandbox' for glob 'mysql*'
Note, selecting 'mysql-client-core-5.5' for glob 'mysql*'
Note, selecting 'mysql-client-core-5.6' for glob 'mysql*'
Note, selecting 'mysql-client-core-5.7' for glob 'mysql*'
Note, selecting 'mysql-testsuite-5.5' for glob 'mysql*'
Note, selecting 'mysql-testsuite-5.6' for glob 'mysql*'
Note, selecting 'mysql-testsuite-5.7' for glob 'mysql*'
Note, selecting 'mysql-common' for glob 'mysql*'
Note, selecting 'mysql-mmm-monitor' for glob 'mysql*'
Note, selecting 'mysqltuner' for glob 'mysql*'
Note, selecting 'mysql-workbench-data' for glob 'mysql*'
Note, selecting 'mysql-server-core-5.1' for glob 'mysql*'
Note, selecting 'mysql-server-core-5.5' for glob 'mysql*'
Note, selecting 'mysql-server-core-5.6' for glob 'mysql*'
Note, selecting 'mysql-server-core-5.7' for glob 'mysql*'
Note, selecting 'mysql-source-5.7' for glob 'mysql*'
Package 'mysql-client-5.5' is not installed, so not removed
Package 'mysql-client-5.6' is not installed, so not removed
Package 'mysql-server-core-5.6' is not installed, so not removed
Package 'mysql-client-core-5.5' is not installed, so not removed
Package 'mysql-client-core-5.6' is not installed, so not removed
Note, selecting 'mysql-common' instead of 'mysql-common-5.6'
Package 'mysql-server-5.6' is not installed, so not removed
Package 'mysql-server-core-5.5' is not installed, so not removed
Package 'mysql-testsuite-5.5' is not installed, so not removed
Package 'mysql-testsuite-5.6' is not installed, so not removed
Package 'mysql-server-5.0' is not installed, so not removed
Package 'mysql-server-5.1' is not installed, so not removed
Package 'mysql-server-core-5.1' is not installed, so not removed
Package 'mysql-client-5.1' is not installed, so not removed
Package 'mysql-mmm-agent' is not installed, so not removed
Package 'mysql-mmm-common' is not installed, so not removed
Package 'mysql-mmm-monitor' is not installed, so not removed
Package 'mysql-mmm-tools' is not installed, so not removed
Package 'mysql-sandbox' is not installed, so not removed
Package 'mysql-utilities' is not installed, so not removed
Package 'mysql-workbench' is not installed, so not removed
Package 'mysql-workbench-data' is not installed, so not removed
Package 'mysqltcl' is not installed, so not removed
Package 'mysqltuner' is not installed, so not removed
Package 'mysql-source-5.7' is not installed, so not removed
Package 'mysql-testsuite' is not installed, so not removed
Package 'mysql-testsuite-5.7' is not installed, so not removed
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:
 mariadb-client : Depends: mariadb-client-10.0 (>= 10.0.33-0ubuntu0.16.04.1) but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

d pkg -l | grep -i mysql

ii  dbconfig-mysql                     2.0.4ubuntu1                               all          dbconfig-common MySQL/MariaDB support
ii  libdbd-mysql-perl                  4.033-1ubuntu0.1                           amd64        Perl5 database interface to the MySQL database
ii  libmysqlclient-dev                 5.7.21-0ubuntu0.16.04.1                    amd64        MySQL database development files
ii  libmysqlclient18:amd64             5.5.53-0ubuntu0.14.04.1                    amd64        MySQL database client library
ii  libmysqlclient20:amd64             5.7.21-0ubuntu0.16.04.1                    amd64        MySQL database client library
ii  mysql-client                       5.7.21-0ubuntu0.16.04.1                    all          MySQL database client (metapackage depending on the latest version)
ii  mysql-client-5.7                   5.7.21-0ubuntu0.16.04.1                    amd64        MySQL database client binaries
ii  mysql-client-core-5.7              5.7.21-0ubuntu0.16.04.1                    amd64        MySQL database core client binaries
ii  mysql-common                       5.7.21-0ubuntu0.16.04.1                    all          MySQL database common files, e.g. /etc/mysql/my.cnf
iU  mysql-server                       5.7.21-0ubuntu0.16.04.1                    all          MySQL database server (metapackage depending on the latest version)
rc  mysql-server-5.5                   5.5.53-0ubuntu0.14.04.1                    amd64        MySQL database server binaries and system database setup
iF  mysql-server-5.7                   5.7.21-0ubuntu0.16.04.1                    amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-5.7              5.7.21-0ubuntu0.16.04.1                    amd64        MySQL database server binaries
ii  mytop                              1.9.1-2                                    all          top like query monitor for MySQL
ii  php-mysql                          1:7.0+35ubuntu6                            all          MySQL module for PHP [default]
ii  php5-mysql                         5.5.9+dfsg-1ubuntu4.20                     amd64        MySQL module for php5
ii  php7.0-mysql                       7.0.22-0ubuntu0.16.04.1                    amd64        MySQL module for PHP
ii  phpmyadmin                         4:4.5.4.1-2ubuntu2                         all          MySQL web administration tool

sudo apt-get purge dbconfig-mysql

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  dbconfig-no-thanks
The following packages will be REMOVED:
  dbconfig-mysql*
The following NEW packages will be installed:
  dbconfig-no-thanks
0 upgraded, 1 newly installed, 1 to remove and 17 not upgraded.
2 not fully installed or removed.
Need to get 1,314 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 mirror://mirrors.ubuntu.com/mirrors.txt xenial/universe amd64 dbconfig-no-thanks all 2.0.4ubuntu1 [1,314 B]
Fetched 1,314 B in 1s (994 B/s)         
dpkg: dbconfig-mysql: dependency problems, but removing anyway as you requested:
 phpmyadmin depends on dbconfig-mysql | dbconfig-no-thanks | dbconfig-common (<< 2.0.0); however:
  Package dbconfig-mysql is to be removed.
  Package dbconfig-no-thanks is not installed.
  Version of dbconfig-common on system is 2.0.4ubuntu1.

(Reading database ... 81675 files and directories currently installed.)
Removing dbconfig-mysql (2.0.4ubuntu1) ...
Selecting previously unselected package dbconfig-no-thanks.
(Reading database ... 81673 files and directories currently installed.)
Preparing to unpack .../dbconfig-no-thanks_2.0.4ubuntu1_all.deb ...
Unpacking dbconfig-no-thanks (2.0.4ubuntu1) ...
Setting up mysql-server-5.7 (5.7.21-0ubuntu0.16.04.1) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2
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-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Setting up dbconfig-no-thanks (2.0.4ubuntu1) ...
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

您有什么想法可以解决这个问题吗?

感谢您的时间。

- -编辑 - -

为了修复这个问题,我删除了所有的 my.cnf 文件。所以我尝试在 /etc/mysql 中使用以下内容创建一个新的文件,但这并没有帮助我解决问题(当我尝试“sudo apt-get install mysql-server mysql-client”时返回的错误仍然相同)。

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

!includedir /etc/mysql/conf.d/

---编辑2---

ln -s /etc/alternatives/my.cnf /etc/mysql/mysql.cnf

sudo apt-get 安装 mysql 服务器 mysql 客户端

Reading package lists... Done
Building dependency tree       
Reading state information... Done
mysql-client is already the newest version (5.7.21-0ubuntu0.16.04.1).
mysql-server is already the newest version (5.7.21-0ubuntu0.16.04.1).
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Setting up mysql-server-5.7 (5.7.21-0ubuntu0.16.04.1) ...
update-alternatives: warning: /etc/alternatives/my.cnf has been changed (manually or by a script); switching to manual updates only
update-alternatives: warning: forcing reinstallation of alternative /etc/mysql/my.cnf because link group my.cnf is broken
update-alternatives: warning: current alternative /etc/mysql/my.cnf is unknown, switching to /etc/mysql/mysql.cnf for link group my.cnf
update-alternatives: warning: not replacing /etc/mysql/my.cnf with a link
chown: invalid user: ‘mysql:mysql’
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
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-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

---编辑3---

sudo apt-get 安装 mysql 服务器 mysql 客户端

Reading package lists... Done
Building dependency tree       
Reading state information... Done
mysql-client is already the newest version (5.7.21-0ubuntu0.16.04.1).
mysql-server is already the newest version (5.7.21-0ubuntu0.16.04.1).
0 upgraded, 0 newly installed, 0 to remove and 35 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Setting up mysql-server-5.7 (5.7.21-0ubuntu0.16.04.1) ...
update-alternatives: error: cannot stat file '/etc/mysql/mysql.cnf': Too many levels of symbolic links
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

mysql-server-5.7 安装失败,因为:

错误:替代路径 /etc/mysql/mysql.cnf 不存在

该错误可能是由 mysql 安装错误引起的。

我假设 /etc/mysql/my.cnf 确实存在,但 /etc/mysql/mysql.cnf 不存在。因此以下步骤可能会有所帮助:

  1. 使用以下命令从 /etc/mysql/my.cnf 创建符号链接,即到 /etc/alternatives/my.cnf 的符号链接:ln -s /etc/mysql/my.cnf /etc/alternatives/my.cnf

  2. 检查从 /etc/alternatives/my.cnf 到 /etc/mysql/mysql.cnf 的默认符号链接是否完整:ls -l /etc/alternatives/my*

  3. 如果输出显示“没有这样的文件或目录”,请使用以下命令创建符号链接:ln -s /etc/alternatives/my.cnf /etc/mysql/mysql.cnf

  4. 现在再次运行 mysql-server 安装。


[编辑]

哦,哦。看来之前的卸载出了点问题。让我们逐个修复错误,直到您可以再次正确安装 mysql。当前错误:

chown:无效用户:'mysql:mysql'

为了修复这个问题,让我们检查(如果缺少创建)“mysql”用户及其“mysql”组:

  • 打开组文件进行编辑:(sudo vi /etc/group编辑该文件时请小心!)
  • 查找以“mysql”开头的行。

    • a) 如果存在,请记住该行末尾的数字。
    • b) 如果没有这样的“mysql”行,则在整个(!) 列表中查找具有最高 1xx 数字的行。在其后添加一个新行并输入“mysql:x:GGG”(将 GGG 替换为最高 1xx 数字 +1)。您添加的行可能如下所示:mysql:x:115。然后保存并退出该文件。
  • 现在打开“vi /etc/passwd”(再次,编辑该文件时也要小心!)
  • 查找包含“mysql”的行。

    • a) 如果存在,请检查该行中的第二个数字。它必须与您之前在组文件中记住/添加的数字相匹配。
    • b) 如果没有这样的“mysql”行,则在 wohle(!) 列表中查找具有最高 1xx 数字的行。在其后添加一个新行并输入“mysql:x:UUU:GGG:MySQL Server,,,:/nonexistent:/bin/false”(将 UUU 替换为此文件中的最高数字 1xx 数字 +1。将 GGG 替换为之前从组文件中记住/添加的数字。)。然后保存并退出该文件。

    • 现在尝试再次安装 mysql-server。

相关内容