我在Windows 10上运行mysql,如何从WSL连接到它的端口

问题描述 投票:0回答:1

当XAMPP mysql服务器位于'localhost'时,mysql(有充分理由)非常努力地连接到套接字文件。但是,由于Win64 mysqld当然不会删除Windows子系统for Linux filesytem中的套接字文件,因此无法通过套接字文件进行连接。如何强制它使用端口?

$ mysql --port=3306 -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directo
ry")

Nmap显示端口3306是可访问的。

$ nmap localhost -p 3306

Starting Nmap 7.60 ( https://nmap.org ) at 2019-04-25 09:58 DST
Problem binding to interface , errno: 92
socket_bindtodevice: Protocol not available
Problem binding to interface , errno: 92
socket_bindtodevice: Protocol not available
Problem binding to interface , errno: 92
socket_bindtodevice: Protocol not available
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0019s latency).

PORT     STATE SERVICE
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

如果我不需要,我宁可不要将mysqld绑定到我的外部网络。

我怎么告诉mysql软件,“看,我知道你的想法,但请使用端口3306,而不是套接字”?我最好也想知道如何告诉PHP。

mysql sockets xampp windows-subsystem-for-linux
1个回答
0
投票

解决了它,你需要添加--protocol=TCP。例:

$ mysql --protocol=TCP -p
Enter password:
ERROR 1045 (28000): Access denied for user 'henk'@'localhost' (using password: YES)

现在它只是我身边的用户/密码问题。

一旦我弄清楚需要设置什么,我将在/etc/mysql/mariadb.conf.d/50-client.cnf/etc/php/7.2/cli/php.ini的设置中进行编辑。

编辑:

sudo vim /etc/mysql/mariadb.conf.d/50-client.cnf,在[client]下用#评论插座线,添加一行读取protocol = TCP。此文件的路径可能与实际的Oracle MySQL安装不同,而不是MariaDB。

[mysql]
# socket = 3306
protocol = TCP

如果您连接到127.0.0.1而不是localhost,PHP的pdo_mysql / mysqli / mysqlnd将使用TCP协议,这适用于localhost套接字文件/ named-pipe启发式。

© www.soinside.com 2019 - 2024. All rights reserved.