[英]WSL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I'm trying to use a fresh installation of MySQL on Windows Subsystem for Linux (Ubuntu) and can't seem to ever connect to it.我正在尝试在 Windows Subsystem for Linux (Ubuntu) 上使用全新安装的 MySQL,但似乎无法连接到它。 I always get the error:
WSL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
我总是收到错误:
WSL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I've tried:我试过了:
--skip-grant-tables
by editing /etc/mysql/mysql.conf.d/mysqld.cnf
and restarting/etc/mysql/mysql.conf.d/mysqld.cnf
并重新启动使用--skip-grant-tables
The file /var/run/mysqld/mysqld.sock
never shows up either, though I figure this is because WSL doesn't have perfect socket support to begin with but it should still work.文件
/var/run/mysqld/mysqld.sock
也永远不会出现,尽管我认为这是因为 WSL 没有完美的套接字支持,但它仍然可以工作。 I suspect the problem might be specific to WSL and maybe I should try updating to WSL2?我怀疑问题可能特定于 WSL,也许我应该尝试更新到 WSL2? I don't know what else the issue could be.
我不知道还有什么问题。
I had the same issue.我遇到过同样的问题。
Follow these steps provided by Microsoft: Add or connect a database with WSL请按照 Microsoft 提供的以下步骤操作: 使用 WSL 添加或连接数据库
sudo apt update
sudo apt update
sudo apt install mysql-server
sudo apt install mysql-server
sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql start
sudo mysql_secure_installation
sudo mysql_secure_installation
sudo mysql
sudo mysql
Put these lines at the end of the file /etc/mysql/my.cnf
将这些行放在文件
/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.
然后将这些命令放在终端
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.然后使用以下命令启动mysql。
mysqld
Then open a new terminal and connect using the below command然后打开一个新终端并使用以下命令进行连接
mysql -uroot -pYourPass
Hopefully, it will work thanks.希望它会起作用,谢谢。
Although M. Hamza Rajput 's answer is working (checked), it might be the case that the problem happens simply because mysql is NOT running尽管M. Hamza Rajput的答案有效(已检查),但问题可能只是因为 mysql 没有运行而发生
Thus, start mysql service:于是,启动mysql服务:
sudo service mysql start
and then you can call the secure installation然后你可以调用安全安装
sudo mysql_secure_installation
I have to run mkdir /var/run/mysqld and then service mysql start everytime I want to run mysql.每次我想运行 mysql 时,我都必须运行 mkdir /var/run/mysqld 然后 service mysql start 。 No clue why... here looking for answers but very annoying.
不知道为什么......在这里寻找答案但很烦人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.