无法在 14.04 上安装 mysql-server

无法在 14.04 上安装 mysql-server

Ubuntu Server 14.04,服务器上的所有内容都已完全更新。无论我怎么尝试,都无法mysql-server安装。我按照以下所有答案操作这个问题,我甚至尝试过sudo apt-get purge mysql.*。但都不起作用。发生了什么事?

我收到错误:

Selecting previously unselected package mysql-server-core-5.5.
Preparing to unpack .../mysql-server-core-5.5_5.5.49-0ubuntu0.14.04.1_amd64.deb ...
Unpacking mysql-server-core-5.5 (5.5.49-0ubuntu0.14.04.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up mysql-common (5.5.49-0ubuntu0.14.04.1) ...
(Reading database ... 110435 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.5_5.5.49-0ubuntu0.14.04.1_amd64.deb ...
You are required to change your password immediately (root enforced)
chfn: PAM: Authentication token is no longer valid; new one required
adduser: `/usr/bin/chfn -f MySQL Server mysql' returned error code 1. Exiting.
dpkg: error processing archive /var/cache/apt/archives/mysql-server-5.5_5.5.49-0ubuntu0.14.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.5_5.5.49-0ubuntu0.14.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

尝试

sudo dpkg -l | grep mysql 

它将列出属于 mysql 的包。

Then try the following command 

sudo apt-get --purge autoremove mysql*
sudo apt-get autoclean 

在那之后

sudo rm -r /var/lib/mysql
sudo rm -r /etc/mysql

完成上述步骤后,尝试再次安装mysql。

答案2

您列出的日志的重要部分是:

You are required to change your password immediately (root enforced)
chfn: PAM: Authentication token is no longer valid; new one required
adduser: `/usr/bin/chfn -f MySQL Server mysql' returned error code 1. Exiting.

这有点令人困惑,因为它发生在安装 MySQL 期间,但这试图解释的是,你的rootUbuntu(不是 MySQL)帐户需要更改。我被GitHub 上的错误报告中也存在类似的错误

sudo chage -l root你可以通过(是的, )来验证这个问题chage。你会看到类似这样的内容:

Last password change                              : password must be changed
Password expires                                  : password must be changed
Password inactive                                 : password must be changed
Account expires                                   : never
Minimum number of days between password change    : 0
Maximum number of days between password change    : 14600
Number of days of warning before password expires : 14

您需要使用 重置 root 密码chpasswd "root:YOURPASSWORD"。(您可以使用 生成随机十六进制密码$(openssl rand -hex 32)。)

您现在应该看到类似这样的内容:

Last password change                              : Oct 17, 2018
Password expires                                  : never
Password inactive                                 : never
Account expires                                   : never
Minimum number of days between password change    : 0
Maximum number of days between password change    : 14600
Number of days of warning before password expires : 14

现在您应该能够成功安装 MySQL!

答案3

完成上述步骤后,请按照以下步骤操作。

sudo apt-get update
sudo apt-get install mysql-server
sudo apt-get update
sudo apt-get install mysql-server-5.6
sudo mysql_secure_installation
mysql --version

答案4

如果您尝试在noninteractive模式下安装它,例如在中Dockerfile,请尝试以下操作:

DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server mysql-client

相关内容