当前位置: 首页>>技术教程>>正文


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

, , , ,

问题描述

我在 ubuntu15.04 中安装或删除部分安装的 mysql-server-5.6 时遇到问题。 \n我收到的错误是

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

有人可以帮我解决这个问题吗?

最佳方案

尝试进行清除,然后 re-install。

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

更新 04.09.2018:\n如果您因 MySQL 进程处于活动状态而在卸载/安装时遇到问题,您可以先尝试此操作,然后再尝试上面的操作:\n 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/

找到here at apt-browse.org

第三种方案

清除/重新安装对我来说也不起作用。我发现了以下”solution”:

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

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

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

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

然后,该包的安装完成,没有错误(因为“不存在”问题可能是 “solved”)。

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

第四种方案

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

如果 my.cnf* 文件丢失,您可以 re-install 包 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

\n 1.Re-install mysql-common

\\n

apt-get install –reinstall mysql-common

\\n

  1. 清除mysql-common

\\n

apt-get purge mysql-common

\\n

第五种方案

确认的。顺序很重要。

apt remove mysql-* mariadb-* --purge
apt install mysql-common
apt install mariadb-common
apt install mariadb-server

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/13815.html,未经允许,请勿转载。