在 Ubuntu 14.04 上安装 mysql 的问题

在 Ubuntu 14.04 上安装 mysql 的问题

输入 mysql“root”密码后不久出现以下错误:

An error occurred while setting the password for the MySQL administrative user. 
This may have happened because the account already has a password, or because of a
communication problem with the MySQL server.

以下是 apt-get install mysql-server 的完整输出:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libaio1 libdbd-mysql-perl libdbi-perl libmysqlclient18 libterm-readkey-perl
  mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server-5.5
  mysql-server-core-5.5
Suggested packages:
  libclone-perl libmldbm-perl libnet-daemon-perl libplrpc-perl
  libsql-statement-perl tinyca mailx
The following NEW packages will be installed:
  libaio1 libdbd-mysql-perl libdbi-perl libmysqlclient18 libterm-readkey-perl
  mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server
  mysql-server-5.5 mysql-server-core-5.5
0 upgraded, 11 newly installed, 0 to remove and 49 not upgraded.
Need to get 0 B/8,797 kB of archives.
After this operation, 93.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
Selecting previously unselected package libaio1:i386.
(Reading database ... 88930 files and directories currently installed.)
Preparing to unpack .../libaio1_0.3.109-4_i386.deb ...
Unpacking libaio1:i386 (0.3.109-4) ...
Selecting previously unselected package mysql-common.
Preparing to unpack .../mysql-common_5.5.40-0ubuntu0.14.04.1_all.deb ...
Unpacking mysql-common (5.5.40-0ubuntu0.14.04.1) ...
Selecting previously unselected package libmysqlclient18:i386.
Preparing to unpack .../libmysqlclient18_5.5.40-0ubuntu0.14.04.1_i386.deb ...
Unpacking libmysqlclient18:i386 (5.5.40-0ubuntu0.14.04.1) ...
Selecting previously unselected package libdbi-perl.
Preparing to unpack .../libdbi-perl_1.630-1_i386.deb ...
Unpacking libdbi-perl (1.630-1) ...
Selecting previously unselected package libdbd-mysql-perl.
Preparing to unpack .../libdbd-mysql-perl_4.025-1_i386.deb ...
Unpacking libdbd-mysql-perl (4.025-1) ...
Selecting previously unselected package libterm-readkey-perl.
Preparing to unpack .../libterm-readkey-perl_2.31-1_i386.deb ...
Unpacking libterm-readkey-perl (2.31-1) ...
Selecting previously unselected package mysql-client-core-5.5.
Preparing to unpack .../mysql-client-core-5.5_5.5.40-0ubuntu0.14.04.1_i386.deb ...
Unpacking mysql-client-core-5.5 (5.5.40-0ubuntu0.14.04.1) ...
Selecting previously unselected package mysql-client-5.5.
Preparing to unpack .../mysql-client-5.5_5.5.40-0ubuntu0.14.04.1_i386.deb ...
Unpacking mysql-client-5.5 (5.5.40-0ubuntu0.14.04.1) ...
Selecting previously unselected package mysql-server-core-5.5.
Preparing to unpack .../mysql-server-core-5.5_5.5.40-0ubuntu0.14.04.1_i386.deb ...
Unpacking mysql-server-core-5.5 (5.5.40-0ubuntu0.14.04.1) ...
Processing triggers for man-db (2.6.7.1-1) ...
Setting up mysql-common (5.5.40-0ubuntu0.14.04.1) ...
Selecting previously unselected package mysql-server-5.5.
(Reading database ... 89293 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.5_5.5.40-0ubuntu0.14.04.1_i386.deb ...
Unpacking mysql-server-5.5 (5.5.40-0ubuntu0.14.04.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.5.40-0ubuntu0.14.04.1_all.deb ...
Unpacking mysql-server (5.5.40-0ubuntu0.14.04.1) ...
Processing triggers for man-db (2.6.7.1-1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up libaio1:i386 (0.3.109-4) ...
Setting up libmysqlclient18:i386 (5.5.40-0ubuntu0.14.04.1) ...
Setting up libdbi-perl (1.630-1) ...
Setting up libdbd-mysql-perl (4.025-1) ...
Setting up libterm-readkey-perl (2.31-1) ...
Setting up mysql-client-core-5.5 (5.5.40-0ubuntu0.14.04.1) ...
Setting up mysql-client-5.5 (5.5.40-0ubuntu0.14.04.1) ...
Setting up mysql-server-core-5.5 (5.5.40-0ubuntu0.14.04.1) ...
Setting up mysql-server-5.5 (5.5.40-0ubuntu0.14.04.1) ...
141117 20:53:10 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.5 (--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.5; however:
  Package mysql-server-5.5 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.19-0ubuntu6.3) ...
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Processing triggers for ureadahead (0.100.0-16) ...
Errors were encountered while processing:
 mysql-server-5.5
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

为了彻底卸载 mysql,我执行了以下步骤:

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get remove --purge mysql-server-core-5.5 mysql-client-core-5.5
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql

这似乎完全删除了所有内容,但随后的安装尝试仍会产生同样的问题。

我还设置了 /tmp 的权限。

值得注意的是,这台机器上安装了 Postgres,但据我所知,这应该不是问题。

提前感谢任何帮助/建议。

答案1

关键线索可能是输出中的这一行:

dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.5; however:
Package mysql-server-5.5 is not configured yet.
  1. 确保 MySQL 已完全删除/清除

    sudo apt-get remove --purge mysql-server mysql-client mysql-common mysql-server-5.5 mysql-client-5.5 mysql-server-core-5.5 mysql-client-core-5.5
    sudo apt-get autoremove
    sudo apt-get autoclean
    sudo rm -rf /var/lib/mysql /etc/mysql
    sudo deluser mysql
    
    sudo apt-get dist-upgrade
    sudo reboot
    sudo apt-get install mysql-server-5.5
    sudo apt-get install mysql-server
    

答案2

我遇到了类似的问题。我尝试将 MariaDB 10.0 与 MySQL Workbench 一起使用,但出现了一些问题,关键是我最终安装和卸载了 MySQL 和 MariaDB 软件包,直到我破坏了所有软件包,并且无法安装 MariaDB 或 MySQL。我花了很长时间试图解决这个问题,最后我找到了一个解决方案,我根据与此问题以及 dpkg 和 apt 问题相关的类似问题找到了解决方案。MariaDB 或 MySQL 也一样。所以...解决方案如下:

我做的和你一样:

sudo aptitude purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo aptitude autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql

从现在起,我根据 dpkg 问题的答案执行了此操作。我不知道这是否最安全,但确实有效:

cd /var/lib/dpkg/info/
sudo rm -rf mysql*

就这样,我再次安装,它就正常工作了。我希望这对某些人有用。

答案3

从你的问题来看,你似乎使用了命令

sudo rm -rf /ver/lib/mysql代替sudo rm -rf /var/lib/mysql

确保 my.cnf 已从 /etc/my.cnf 位置删除。

sudo rm /etc/my.cnf

sudo apt-get remove mysql-server mysql-client mysql-common

完成后,尝试再次重新安装 mysql 服务器。

相关内容