我在Windows 10上运行mysqld,如何从WSL连接到其端口

Henk Polary

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

$ 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。

Henk Polary

解决后,您需要添加--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套接字文件/命名管道启发式方法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

连接到Windows 10上运行mysql的Docker容器

如何让 Ubuntu 20.04 在 Windows 10 WSL 2 上运行?

无法在Windows 10上我学校的Wi-Fi网络上连接到Internet

将蓝牙耳机连接到手机后,如何防止其连接到Windows 10计算机?

无法在Windows 10上连接到VPN

无法正确连接到Windows VM上的开放端口

将VisualVM连接到Windows 8.1下在OpenJDK 10上运行的程序不起作用

如何从WSL连接到Windows Postgres数据库

如何从 WSL 连接到本地 Windows SQL Server 实例?

如何将wsl连接到Windows本地主机?

Windows 10 Spring更新(2018)中的WSL是否允许我在其上运行docker?为什么呢?

如何查看我是否连接到临时端口?

如何指示 PowerShell 7 在 Windows 10 上的 WSL2 中运行 bash (Ubuntu) 脚本?

VirtualBox 5.0.10拒绝在我的Windows 10上运行

无法在我的 Windows 10 和 Windows 10 上的 linux 子系统上运行 bash

Windows上的Ubuntu上的Bash(10)-无法连接到Upstart

我可以在Windows上运行Wine吗?

我可以在Windows上运行Airflow吗?

我的Windows 10是正版吗?

我想从Windows 10迁移

如何使用SQLAlchemy在Windows 10中的Docker上连接到Postgres数据库?

如何检测我的应用程序是否在Windows 10上运行

无法通过运行OpenSSH的SSH连接到Windows 10

我无法在Windows 10上安装wingw

我的Windows 10上没有Cortana

我的 Windows 10 上的双启动 Ubuntu

无法连接到我在Azure VM上运行的网站

连接到在我的pi上运行的flask应用程序

无法连接到在我的Mac上运行的mysql