WSL: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

Source : windows subsystem for linux – WSL: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) – Stack Overflow

Put these lines at the end of the file /etc/mysql/my.cnf:

[mysqld]                                                                                                                
bind-address = 0.0.0.0                                                                                                    
user=root                                                                                                               
pid-file     = /var/run/mysqld/mysqld.pid                                                                                
socket       = /var/run/mysqld/mysqld.sock                                                                               
port         = 3306                                                                                                                                                                                                                              

[client]                                                                                                                
port         = 3306                                                                                                      
socket       = /var/run/mysqld/mysqld.sock

Then put these commands on terminal (NOTE: if dir is not there then create one):

chmod 777 -R /var/run/mysqld
chmod 777 -R /var/lib/mysql
chmod 777 -R /var/log/mysql

Then start MySQL using below command:

mysqld

Then open a new terminal and connect using the below command:

mysql -u root -p YourPass
What are your feelings
Updated on May 14, 2024