我在 Windows 10 Pro 中使用 wsl2。我尝试了很多次安装 mysql,但每次都出现此错误。我尝试使用以下命令卸载并再次安装:
sudo service mysql stop
sudo apt purge mysql-server mysql-client mysql-common
sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql
sudo apt autoremove
sudo apt autoclean
并再次安装。
我得到了这个错误
Unpacking mysql-server (8.0.29-0ubuntu0.22.04.3) ...
Setting up mysql-client-8.0 (8.0.29-0ubuntu0.22.04.3) ...
Setting up mysql-server-8.0 (8.0.29-0ubuntu0.22.04.3) ...
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)
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 4602
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
No apport report written because the error message indicates its a followup error from a previous failure.
dpkg: dependency problems prevent configuration of 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
Processing triggers for man-db (2.10.2-1) ...
Errors were encountered while processing:
mysql-server-8.0
mysql-server
needrestart is being skipped since dpkg has failed
E: Sub-process /usr/bin/dpkg returned an error code (1)
答案1
我想说的是@Ashish Thakur 的评论对我有帮助。我之前在 Windows 上安装了 MySQL,然后又想通过 WSL 安装它。因此,在我停止 Windows 服务中的 MYSQL 实例的服务后,我可以在 Ubuntu (WSL) 上成功安装 MySQL。
答案2
要安装 mySQL,您需要确保您的其他 WSL 环境均未运行它。您只能在一个环境中运行 mySQL。