WSL:无法通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器(2) [英] WSL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

查看:80
本文介绍了WSL:无法通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器(2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在适用于 Linux 的 Windows 子系统 (Ubuntu) 上使用全新安装的 MySQL,但似乎无法连接到它.我总是收到错误:WSL: 无法通过socket'/var/run/mysqld/mysqld.sock'连接本地MySQL服务器(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. I always get the error: WSL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我试过了:

  • 将配置切换为使用 localhost 而不是套接字(我收到一个错误,说我无法通过 localhost 连接)
  • 使用--skip-grant-tables,编辑/etc/mysql/mysql.conf.d/mysqld.cnf并重启
  • Switching the configuration to use localhost instead of sockets (I instead get an error saying I can't connect through localhost)
  • Using --skip-grant-tables by editing /etc/mysql/mysql.conf.d/mysqld.cnf and restarting

文件 /var/run/mysqld/mysqld.sock 也从来没有出现过,尽管我认为这是因为 WSL 一开始没有完美的套接字支持,但它应该仍然可以工作.我怀疑这个问题可能是 WSL 特有的,也许我应该尝试更新到 WSL2?我不知道还有什么问题.

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. I suspect the problem might be specific to WSL and maybe I should try updating to WSL2? I don't know what else the issue could be.

推荐答案

我通过以下步骤解决了同样的问题.

将这些行放在文件的末尾/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

然后将这些命令放在终端上 注意:如果目录在那里,则创建一个.

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

然后使用下面的命令启动mysql.

mysqld

然后打开一个新终端并使用以下命令连接

mysql -uroot -pYourPass

希望它能奏效,谢谢.

这篇关于WSL:无法通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆