Skip to content

Commit cf5ebb2

Browse files
authored
Merge pull request #4 from BruceFletcher/master
Added MySQL relay script and documentation
2 parents 0755886 + b4c7b89 commit cf5ebb2

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use Windows named pipes from the Windows Subsystem for Linux (WSL).
77
For example, you can:
88

99
* Connect to Docker for Windows from the Linux Docker client in WSL
10+
* Connect to MySQL Server running as a Windows service
1011
* Connect interactively to a Hyper-V Linux VM's serial console
1112
* Use gdb to connect to debug the kernel of a Hyper-V Linux VM
1213

@@ -105,6 +106,45 @@ $ sudo adduser <my_user> docker
105106

106107
Then open a new WSL window to reset your group membership.
107108

109+
## Connect to MySQL Server running as a Windows service
110+
111+
If you run MySQL Server as a Windows service, you can configure it to
112+
communicate through TCP, named pipes or shared memory. If you use named
113+
pipes, connecting to MySQL from WSL is very similar to connecting
114+
to Docker.
115+
116+
The `mysqld-relay` script is designed to be run in a `sudo` shell.
117+
Before creating the relay, it will try to configure your environment
118+
(if it has not been configured yet) by:
119+
120+
* creating `/var/run/mysqld/`,
121+
* creating a `mysql` group, and
122+
* adding your user account to the `mysql` group.
123+
124+
You can of course pull out just the npiperelay command if you don't
125+
need any of the above checks.
126+
127+
Note that if you need to enter a password for sudo, the following
128+
command will fail because of the lack of password input:
129+
130+
```bash
131+
$ sudo mysqld-relay &
132+
```
133+
134+
In that case, you can run it like this:
135+
136+
```bash
137+
user@machine:~$ sudo -s
138+
[sudo] password for user:
139+
root@machine:~# mysqld-relay &
140+
root@machine:~# exit
141+
user@machine:~$ _
142+
```
143+
144+
Now you can use the Linux `mysql` command line client or any other
145+
Linux process that expects to talk to MySQL Server through
146+
`/var/run/mysqld/mysqld.sock`.
147+
108148
## Connecting to a Hyper-V Linux VM's serial console
109149

110150
If you have a Linux VM configured in Hyper-V, you may wish to use its serial

scripts/mysqld-relay

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
if [ -z "${SUDO_USER+x}" ]; then
4+
echo "mysqld-relay must be run via 'sudo'"
5+
exit 1
6+
fi
7+
8+
if [ ! -e /var/run/mysqld ]; then
9+
mkdir /var/run/mysqld
10+
fi
11+
12+
if [ ! $(getent group exists mysql) ]; then
13+
groupadd mysql
14+
fi
15+
16+
if $(id -Gn $SUDO_USER | grep -qv '\bmysql\b'); then
17+
usermod -aG mysql $SUDO_USER
18+
echo "*** Log out and back in to enable 'mysql' group membership ***"
19+
fi
20+
21+
exec socat UNIX-LISTEN:/var/run/mysqld/mysqld.sock,fork,group=mysql,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/MYSQL",nofork

0 commit comments

Comments
 (0)