在 Ubuntu 16.04 上安装 mySql 时出错

在 Ubuntu 16.04 上安装 mySql 时出错

我一直遵循这一页 在 Ubuntu 16.04 上安装 mysql。

我在该页面的“MySQL 安装和配置”部分中途运行了命令sudo apt-get install mysql-server。但是,我遇到了错误,以下是该错误在我的终端中的输出:

Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 41515 files and directories currently installed.)
Preparing to unpack .../mysql-common_5.7.12-0ubuntu1_all.deb ...
Unpacking mysql-common (5.7.12-0ubuntu1) ...
Selecting previously unselected package mysql-client-5.7.
Preparing to unpack .../mysql-client-5.7_5.7.12-0ubuntu1_amd64.deb ...
Unpacking mysql-client-5.7 (5.7.12-0ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up mysql-common (5.7.12-0ubuntu1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Selecting previously unselected package mysql-server-5.7.
(Reading database ... 41563 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.7_5.7.12-0ubuntu1_amd64.deb ...
Unpacking mysql-server-5.7 (5.7.12-0ubuntu1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.12-0ubuntu1_all.deb ...
Unpacking mysql-server (5.7.12-0ubuntu1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up mysql-client-5.7 (5.7.12-0ubuntu1) ...
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
mysql_upgrade: Got error: 1045: Access denied for user 'debian-sys-maint'@'localhost' (using password: YES) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
mysql_upgrade failed with exit status 11
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
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
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

这是我第一次设置服务器并安装 mysql。不确定这是否是导致错误的可能原因,但我之前曾尝试安装 mysql,但没有遵循 LAMP 流程(我是新手,不知道如何解决),但失败了,我不得不卸载。

答案1

这个答案也是回答16.04 升级导致 mysql-server 崩溃但我无法回答,因为管理员将其锁定为 10 点声誉。

在将 Ubuntu 升级到 16.04 (xenial) 并将 Mysql 从 5.5 升级到 5.7 时,APT 中发生了错误。由于一些打包问题,APT 升级陷入困境,因为 Mysql-server-5.7 的安装后脚本无法完成。

要解决该问题,请尝试以下步骤:

  1. apt purge mysql-serverapt autoremove清除旧MYSQL的所有痕迹。数据库数据不会被破坏。
  2. 从目录中删除所有内容/etc/mysql
  3. 验证没有安装旧的 Mysql 包:dpkg -l | grep mysql
  4. apt install mysql-server安装

如果这些步骤仍导致安装不完整,请尝试下一步:

  1. Tail -n 20 /var/log/mysql/error.log
  2. 错误可能是 a. debian-sys-maint 的密码错误 b. Innodb 没有内存

解决 2a:您需要将 Mysql 系统表从 5.5 升级到 5.7

编辑 my.cnf,在‘[mysqld]’下添加“skip-grant-tables”行,service mysql start然后mysql_upgrade --force -u root -p

解决 2b:Mysql Innodb 池内存不足(您在微型服务器上吗?)

编辑 my.cnf,在‘[mysqld]’下添加行 innodb_buffer_pool_size = 20M

默认的 innodb 池是 128M,在 512M 的虚拟机中,这个容量比较紧张

要清除 APT 错误,请再次执行安装后操作

dpkg --configure -a

答案2

另一个好的解决方案:

sudo apt-get purge mysql* && sudo apt-get install mysql-server

答案3

彻底删除 mysql 并重新安装是我最终想到的解决方案。虽然我曾尝试卸载并重新安装一次,但没有成功(因此我才提出这个问题)。在找到此页面上的建议后,我尝试了更彻底的卸载: 彻底卸载 MySQL

按照那里的卸载说明并重新安装解决了问题。

答案4

尝试删除所有包和文件,然后重新安装“mysql-server”

sudo apt-get remove --purge mysql-\*
sudo rm -rf /var/lib/mysql

sudo apt-get install mysql-server 

相关内容