Forums

MysqlWorkBench: Cannot Connect to Database Server

I have been using MysqlWorkBench to manage my database in the pythonanywhere server for a few months with no problems. Out of the blue, I get this message and I can't connect:

Your connection attempt failed for user 'username' from your host to server at db1.mysql.pythonanywhere-services.com:3306:
  Lost connection to MySQL server at 'reading initial communication packet', system error: 0

Failed to Connect to MySQL at db1.mysql.pythonanywhere-services.com:3306 through SSH tunnel at ssh.pythonanywhere.com with user username. Lost connection to MySQL server at 'reading initial communication packet', system error: 0

As a side note, I was never able to connect via terminal to the pythonanywhere database.

mysql -u username -h username.mysql.pythonanywhere-services.com -p
ERROR 2003 (HY000): Can't connect to MySQL server on 'username.mysql.pythonanywhere-services.com' (60)

MysqlWorkBench was working fine so I just worked with it. Now I can't connect neither way and don't have access to the DB.

Any thoughts?

oh. just a quick check- you are replacing username with your actual user name right?

Yes, that is correct.

Re. your side note, I get a similar (?) problem here from a PA Bash shell:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I used to connect via something like this but haven't tried for some time.

@jgmdavies what was the command that you ised to connect?

@conrad This was just using a MySQL console created from the PA Consoles tab.

hmm. will investigate.

@pulpiwapi another thing to check- when you say "connect via terminal to the pythonanywhere database", were you connecting from within a pythonanywhere console or from your local machine? If you are connecting from your local machine, were you using ssh tunnelling?

@jgmdavies your error sounds like you hadn't specified the host when trying to connect (would make sense if you had run mysql without a -h from the bash console, but wouldn't make sense if this was a mysql console created directly from the databases tab)

Sorry Conrad - that was a typo earlier, I meant a Bash shell from the PA Consoles tab, as per my first post here.

I just tried it again and it was fine.

@conrad I am trying to connect from my local machine to my Mysql database in the PA server. By the way, thanks for pointing that out, now I was able to connect through the PA console and also from my local machine terminal using:

mysql -u username -h username.mysql.pythonanywhere-services.com -p

But I still get an error when using MysqlWorkBench. It was working fine and suddenly wasn't working anymore: enter image description here

Can you create an ssh connection at all? Could it be your work firewall dropping the ssh connection?

Yes, now I am able to connect from my local machine terminal to the PA servers with an ssh connection. Using:

ssh -L 3306:username.mysql.pythonanywhere-services.com:3306 username@ssh.pythonanywhere.com

I am still trying to figure it out why MysqlWorkBench doesn't work. Doesn't seem to be a firewall issue, it won't connect even when I turn off the firewall.