Forums

ssh connection works. mysql command doesn't

I am able to use ssh on a windows machine to connect to pythonanywhere's hostname. I get a $ prompt as expected. When I try to execute mysql localhost -u <myid> -p or mysql -h 127.0.0.1 -u 127.0.0.1 -p I get Enter password: <as expected> That means the mysql command is working and connecting to the remote host or it wouldn't ask for a password. However, when I supply the password, I get: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' I used cd to follow the path above, I find that there is no mysqld folder. /run/ has: 00:16 /var/run $ pwd /var/run 00:25 /var/run $ ls dnsmasq init.upgraded log mount screen shm user initctl lock motd.dynamic postgresql sendsigs.omit.d systemd utmp 00:25 /var/run $

I can use the mysql console in pythonanywhere. Is remote access not enabled? I have a paid account but I just created it about two hours ago.

You're trying to connect to a MySQL server on localhost from the SSH server. We do not run the MySQL servers on the SSh machine. Use the connection details for your database from the Databases tab to connect from the SSh session.

I'm trying to follow the instructions on this page:
https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere/
The bottom two sections in the help doc are "Manual SSH Tunneling" and "Using the Tunnel".
Looks like it should work, but doesn't.
The SSH connection is established as follows:
ssh -L 3306:<myid>.mysql.pythonanywhere-services.com:3306 <myid>@ssh.pythonanywhere.com
If I understand correctly, this command [with -L] "port forwards" 3306 from the ssh server to the mysql server.
From that prompt, I can see the following:

15:26 ~ $ hostname
green-liveconsole1
15:26 ~ $ pwd
/home/compunuke
15:26 ~ $</br>

The mysql command then:
mysql -h 127.0.0.1 -u username -p
should be forwarding to mysql.pythonanywhere-services.com:3306.
The fact that it then asks for my password suggests that mysql on the target server must be responding.
The SSH server would not ask for my MySQL password since MySQL is not running there.
Am I correct or am I still missing something?

That will only be forwarded to the PythonAnywhere MySQL server if you're running it in a different console. Otherwise, you are running it on PythonAnywhere. The password prompt is shown before the connection attempt because of the -p argument. If you do it without the -p, you will get a connection refused, because there is no MySQL server running on the SSH server.