无法在纯Ubuntu 20.04上安装mysql

时间:2020-06-01 08:01:46

标签: mysql ubuntu windows-subsystem-for-linux

我刚刚安装了WSL Ubuntu 20.04,我要做的第一件事是

 sudo apt-get update
 sudo apt-get upgrade
 sudo apt-get install mysql-server

在这里给了我

Setting up mysql-server-8.0 (8.0.20-0ubuntu0.20.04.1) ...
invoke-rc.d: could not determine current runlevel
 * Stopping MySQL database server mysqld                                                                                                                         [ OK ]
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Cannot open /proc/net/unix: No such file or directory
Cannot stat file /proc/1/fd/5: Operation not permitted
Cannot stat file /proc/1/fd/10: Operation not permitted
Cannot stat file /proc/1/fd/6: Operation not permitted
Cannot stat file /proc/42/fd/7: Operation not permitted
Cannot stat file /proc/42/fd/10: Operation not permitted
Cannot stat file /proc/42/fd/5: Operation not permitted
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 3726
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package mysql-server-8.0 (--configure):
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1

dpkg:依赖性问题阻止了mysql-server的配置:

 mysql-server depends on mysql-server-8.0; however:
  Package mysql-server-8.0 is not configured yet.

    dpkg: error processing package mysql-server (--configure):
     dependency problems - leaving unconfigured
    Setting up libcgi-pm-perl (4.46-1) ...
    No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                              Setting up libhtml-template-perl (2.97-1) ...
    Setting up libcgi-fast-perl (1:2.15-1) ...
    Processing triggers for systemd (245.4-4ubuntu3.1) ...
    Processing triggers for man-db (2.9.1-1) ...
    Processing triggers for libc-bin (2.31-0ubuntu9) ...
    Errors were encountered while processing:
     mysql-server-8.0
     mysql-server
    E: Sub-process /usr/bin/dpkg returned an error code (1)

然后我尝试了sudo mysql_secure_installation

Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

这不仅限于WSL。

3 个答案:

答案 0 :(得分:1)

我和你有同样的问题;我在 Windows 10 中使用Ubuntu 20.04 WSL版本进行了以下操作,它对我有帮助。 首先,由于出现dependency problems - leaving unconfigured错误,我跟随this answer here清除 MySQL 并尝试重新安装:

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

sudo apt-get install mysql-server

这样做仍然可以解决问题(但是无论如何肯定会有所帮助)。

下一个线索是Can't connect to local MySQL server through socket错误... MySQL 命令正在询问密码,并提供错误的密码导致此错误。尚未设置密码,对吗?错误!读取MySQL 8.0 Reference Manual - Default Privileges安装会首先设置一个随机密码。因此,必须先更改 root 密码。

为此,我遵循了this answer。为了方便起见,我在此处复制该答案:

在ubuntu上,我执行了以下操作:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking

然后在新终端中运行mysql:

mysql -u root

并运行以下查询以更改密码:

UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;

在MySQL 5.7中,删除了mysql.user表字段中的password字段,现在该字段名称为“ authentication_string”。

引用答案后,请注意,PASSWORD()函数已不建议在this answer over here中共享。如此处所述,只需使用我使用过的MD5()的任何MySQL encryption functions替换它即可。

最后:

sudo service mysql start
* Starting MySQL database server mysqld                     [ OK ]

答案 1 :(得分:1)

作为第一步,请尝试这些步骤

sudo apt-get remove --purge mysql*

sudo apt-get purge mysql*

sudo apt-get autoremove

sudo apt-get autoclean

sudo apt-get remove dbconfig-mysql

sudo apt-get dist-upgrade

如果您遇到相同的错误,请尝试删除 MySQL dpkgs。为此,请尝试以下步骤

dpkg -l | grep mysql

然后你会看到mysql的包并一一删除

sudo apt purge [package_name]

sudo dpkg purge [package_name]

虽然有些 pkgs 不会被删除。保持原样并尝试安装 mysql 服务器

sudo apt update

sudo apt install mysql-server

sudo mysql_secure_installation

希望你能得到答案。 谢谢。

答案 2 :(得分:0)

安装冻结时

> sudo killall mysqld

并继续安装