在Ubuntu中安装和删除MySQL时遇到问题

我在ubuntu15.04中安装或删除部分安装的mysql-server-5.6时遇到了麻烦。 我得到的错误是

$ sudo apt-get -f install Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: mysql-server-5.6 The following packages will be upgraded: mysql-server-5.6 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 22 not fully installed or removed. Need to get 0 B/5,501 kB of archives. After this operation, 50.8 MB of additional disk space will be used. Do you want to continue? [Y/n] Preconfiguring packages ... Setting up mysql-common (5.6.24-0ubuntu2) ... update-alternatives: error: alternative path /etc/mysql/my.cnf.fallback doesn't exist dpkg: error processing package mysql-common (--configure): subprocess installed post-installation script returned error exit status 2 Errors were encountered while processing: mysql-common localepurge: Disk space freed in /usr/share/locale: 0 KiB localepurge: Disk space freed in /usr/share/man: 0 KiB localepurge: Disk space freed in /usr/share/gnome/help: 0 KiB localepurge: Disk space freed in /usr/share/omf: 0 KiB localepurge: Disk space freed in /usr/share/doc/kde/HTML: 0 KiB Total disk space freed by localepurge: 0 KiB E: Sub-process /usr/bin/dpkg returned an error code (1) 

有人可以帮我吗?

尝试清除,然后重新安装。

 sudo apt-get remove --purge mysql-\* sudo apt-get install mysql-server mysql-client 

更新04.09.2018:
如果由于MySQL进程处于活动状态而卸载/安装时出现问题,您可以先尝试,然后再尝试:
sudo kill $(pgrep mysql)

我(linux noob)必须挖掘的一个非常简单的解决方案是创建文件。

 nano /etc/mysql/my.cnf.fallback 

并使用mysql-common 5.7.11-0ubuntu6包中的默认内容填充它。

 # # 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/ 

在apt-browse.org找到了

清除/重新安装也不适用于我。 我找到了以下“解决方案”:

我找不到mysql-server-5.6 / mysql-client-5.6的“提供的文件”中列出的mysql.cnf.fallback ,也没有关于该文件的任何其他信息。

我将/etc/mysql/my.cnf复制到/etc/mysql/my.cnf.fallback (猜测这可能是一个相对不太重要的“后备”配置文件);

/etc/mysql/my.cnf是一个符号链接,所以ls /etc/mysql现在显示:

  my.cnf.fallback -> /etc/alternatives/my.cnf my.cnf -> /etc/alternatives/my.cnf 

然后完成包的安装而没有错误(因为可能“不存在”问题被“解决”)。

我还没有遇到任何不利影响。

我在尝试清除mysql-server时遇到了同样的问题(5.7.14)。

如果缺少my.cnf *文件,你可以重新安装mysql-common软件包,然后你可以清除它们( mysql-server和mysql-common

这些my.cnf *文件属于mysql-common软件包(见下文):

 $ dpkg -L mysql-common | grep cnf /etc/mysql/my.cnf.fallback /etc/mysql/conf.d/mysql.cnf 

1. 重新安装mysql-common

apt-get install –reinstall mysql-common

  1. 清除mysql-common

apt-get purge mysql-common

我检查了我的/etc/mysql/文件夹,发现除了空的子文件夹conf.d之外它是完全空的。

 cd /etc/ # you need to delete the empty mysql folder otherwise the ln below creates the link inside the existing mysql folder sudo rm -r mysql sudo ln -s ./mysql.bak/ mysql 

然后(由此链接提供此链接 )

 sudo dpkg --configure -a 

现在一切都好看了。

上面的链接也提到--force-depends但我不需要这个。 它还提到了apt-get -f install但我不再需要这个。

正如charneykaye在评论中所指出的,如果后台有一些mysql进程,这种方法可能会失败。 我用了:

 emil-mint-desktop ~ # ps -aef | grep mysql root 6682 1 0 16:45 ? 00:00:00 sudo mysqld_safe --skip-grant-tables root 6683 6682 0 16:45 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables mysql 7046 6683 0 16:45 ? 00:00:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 --log-syslog=1 --log-syslog-facility=daemon --log-syslog-tag= root 21046 9812 0 17:32 pts/5 00:00:00 grep --color=auto mysql 

杀死前3个进程(最后一个是grep调用本身!)使用:

 kill -9 6682 8883 7046 

然后删除所有相关的mysql

 apt remove --purge mysql-\* apt autoremove apt autoclean 

然后安装:

 apt install mysql-server 

然后它奏效了。

版本:

  • Mint 18.1(基于Ubuntu)。 对于其他一些版本,您需要将apt替换为apt-get

我找到了一个简单的解决方案:

第一步: apt-get install mysql-common --reinstall

第二步: apt-get install mysql-server --reinstall

它的工作原理!

在尝试了上述所有答案后,我能够解决此问题:

sudo rm /etc/rc5.d/S03mysql

然后能够运行:

sudo apt purge mysql-server mysql-server-5.7 mysql-server-core-5.7

sudo apt-get -f install mysql-server –fix-missing –fix-broken