WSL2 安装MySQL踩坑
qiuliw@X:/opt/mysql$ sudo apt-get install ./mysql-server_5.7.29-1ubuntu18.04_amd64.deb
[sudo] password for qiuliw:
qiuliw@X:/opt/mysql$ sudo apt-get install ./mysql-server_5.7.32-1ubuntu18.04_amd64.deb
[sudo] password for qiuliw:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'mysql-server' instead of './mysql-server_5.7.32-1ubuntu18.04_amd64.deb'
mysql-server is already the newest version (5.7.32-1ubuntu18.04).
0 upgraded, 0 newly installed, 0 to remove and 489 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up mysql-community-server (5.7.32-1ubuntu18.04) ...
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.
invoke-rc.d: initscript mysql, action "start" failed.
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2025-07-02 13:30:55 CST; 5ms ago
Process: 2333 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
CPU: 253ms
dpkg: error processing package mysql-community-server (--configure):
installed mysql-community-server package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-community-server (= 5.7.32-1ubuntu18.04); however:
Package mysql-community-server is not configured yet.
dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
mysql-community-server
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
看报错日志是端口被占用,但是netstat/ss/lsof又查不到端口的线程,以为是依赖问题。
直到看到了 https://zhuanlan.zhihu.com/p/712920244 提到端口被主机占用,改了端口马上就好了
# /etc/mysql/my.cnf
[mysqld]
port=3307
WSL2开启了主机网络镜像模式,与主机共享IP端口,但是netstat/ss/lsof 等工具只能查看 WSL2 内部的端口使用情况

浙公网安备 33010602011771号