【问题标题】:I run mysqld on Windows 10, how do I connect to its port from WSL我在 Windows 10 上运行 mysql,如何从 WSL 连接到它的端口
【发布时间】:2019-09-14 14:42:08
【问题描述】:

mysql(有充分的理由)在 XAMPP mysql 服务器位于“localhost”时非常努力地连接到套接字文件。但是由于 Win64 mysqld 当然不会在 Windows Subsystem for 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 传达同样的信息。

【问题讨论】:

    标签: mysql sockets xampp windows-subsystem-for-linux


    【解决方案1】:

    已解决,需要添加--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] 下用# 注释掉socket 行,添加一行protocol = TCP。此文件的路径可能与实际安装的 Oracle MySQL 不同,而不是 MariaDB。

    [mysql]
    # socket = 3306
    protocol = TCP
    

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

    【讨论】:

      猜你喜欢
      • 2019-06-19
      • 2021-03-04
      • 1970-01-01
      • 2017-01-19
      • 2014-01-15
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多