Issue
I am running MySQL on WSL2 for Windows. At WSL2 startup, MySQL does not start and I get the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I then run this command to get it going:
sudo service mysql start
And get the following output:
* Starting MySQL database server mysqld
su: warning: cannot change directory to /nonexistent: No such file or directory
[ OK ]
When I check my MySQL error logs, I see this error regarding max_open_files and 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)
My understanding is I need to edit my /lib/systemd/system/mysql.service file to change this, but when I check that file I see that LimitNOFILE is already set to 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
It's almost as if that setting get's ignored at service startup? Does anyone know where the right place is to set it if this isn't?
Solution
You need to check information in /etc/security/limits.conf
You can add something like (assuming you run mysqld
as mysql
user)
mysql hard nofile 10000
mysql soft nofile 8192
and in my.cnf
[mysqld]
open_files_limit = 10000
table_open_cache=4096
then logout, login and restart mysql
Answered By - Romeo Ninov Answer Checked By - David Goodson (WPSolving Volunteer)