Henk Poley
Henk Poley

Reputation: 819

I run mysqld on Windows 10, how do I connect to its port from WSL

mysql (for good reasons) tries very hard to connect to the socket file when the XAMPP mysql server is at 'localhost'. But since Win64 mysqld of course does not drop a socket file inside the Windows Subsystem for Linux filesytem, it can't connect through the socket file. How do I force it to use the port?

$ 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 shows port 3306 is accessible.

$ 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

I'd rather not not bind mysqld to my outside network if I don't need to.

How do I tell the mysql software, "Look I know what you think, but please use port 3306, and not the socket"? Preferably I'd like to know how to tell the same to PHP too.

Upvotes: 4

Views: 6905

Answers (1)

Henk Poley
Henk Poley

Reputation: 819

Resolved it, you need to add --protocol=TCP. Example:

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

Now it's simply a user/password problem on my side.

I'll edit in the setting for /etc/mysql/mariadb.conf.d/50-client.cnf, /etc/php/7.2/cli/php.ini once I figure out what the settings need to be.

Edit:

sudo vim /etc/mysql/mariadb.conf.d/50-client.cnf, under [client] comment out the socket line with a #, add a line that reads protocol = TCP. The path of this file might be different with an actual Oracle MySQL install, instead of MariaDB.

[mysql]
# socket = 3306
protocol = TCP

PHP's pdo_mysql/mysqli/mysqlnd will use the TCP protocol if you connect to 127.0.0.1 instead of localhost, this works around the localhost socket file / named-pipe heuristics.

Upvotes: 3

Related Questions