我正在WSL2上运行WSL2 for Windows。在WSL2启动时,MySQL没有启动,我得到以下错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
然后运行以下命令以使其正常运行:
sudo service mysql start
并获得以下输出:
* Starting MySQL database server mysqld
su: warning: cannot change directory to /nonexistent: No such file or directory
[ OK ]
当我检查我的MySQL错误日志时,我看到有关max_open_files和table_open_cache的这个错误:
2022-07-28T08:36:34.074107Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
2022-07-28T08:36:34.074111Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
我的理解是,我需要编辑我的/lib/systemd/system/mysql.service文件来更改它,但是当我检查该文件时,我发现LimitNOFILE已经设置为10000。
# MySQL systemd service file
[Unit]
Description=MySQL Community Server
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
User=mysql
Group=mysql
PIDFile=/run/mysqld/mysqld.pid
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/sbin/mysqld
TimeoutSec=infinity
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755
LimitNOFILE=10000
# Set enviroment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
就好像这个设置在服务启动时被忽略了一样?如果不是,有人知道该放在哪里吗?
发布于 2022-07-28 01:12:23
您需要在/etc/security/limits.conf
中检查信息,您可以添加类似的内容(假设您以mysql
用户的身份运行mysqld
)。
mysql hard nofile 10000
mysql soft nofile 8192
在my.cnf
中
[mysqld]
open_files_limit = 10000
table_open_cache=4096
然后退出,登录并重新启动mysql
https://stackoverflow.com/questions/73149933
复制