What ended up solving the problem was changing the PuTTY settings to:
Apparently, port 33060
uses the X protocol, not the classic MySQL protocol.
From my testing, it seems changing the port makes a difference with the Ubuntu MySQL client (even though the Windows MySQL server port is exactly the same and SELECT @@global.protocol_version;
shows 10
).
After changing the PuTTY settings, I was then able to connect on my Ubuntu VPS with this command:
mysql -h 127.0.0.1 -P 3307 -u test -ptest
However, running the same command with localhost
instead of 127.0.0.1
gives an Access Denied
error. After some digging, I found this post which explains:
"In MySQL, the localhost keyword is reserved for connection using the MySQL socket and you should use the ip-address 127.0.0.1 for TCP connections to the MySQL network port on 127.0.0.1."
The ssh
equivalent command (built into Windows and enabled in April 2018 update) is:
ssh -R 3307:localhost:33060 username@your_ip -i "C:\path\to\your\id_rsa" -o "StrictHostKeyChecking=no"
To create a persistent reverse tunnel as a Windows service, see this autossh guide.
There are a few oversights and errors in the guide though.
When installing cygwin
, you'll need to install these packages:
cygrunsrv
openssh
autossh
Then allow your Windows account to Log On as a Service:
WinKey + R -> gpedit.msc
Computer Configuration -> Windows Settings -> Security Settings -> Local Policies -> User Rights Assignment -> Log on as a service -> Add your username.
To test your autossh
connection in a cygwin
instance:
autossh -M 20000 -R 3307:localhost:33060 username@your_ip -i "C:\path\to\your\id_rsa" -o "StrictHostKeyChecking=no"
If that works, open PowerShell as an admin (important) and run:
C:\cygwin64\bin\cygrunsrv.exe -I AutoSSH -p /usr/bin/autossh -a '-M 20000 -R 3307:localhost:33060 username@your_ip -i "C:\\path\\to\\your\\id_rsa" -o "StrictHostKeyChecking=no"' -e AUTOSSH_NTSERVICE=yes
Note the double backslashes.
Later, if the service doesn't start and you need to try again, run this command in the admin PowerShell to delete the service:
sc.exe delete AutoSSH
In cygwin
you can find the AutoSSH log in /var/log/AutoSSH.log
to diagnose errors.