Forums

mysql -h 127.0.0.1 -u username -p returns "Can't connect to MySQL server on '127.0.0.1' (111)"

I'm trying to establish a remote connection to my PythonAnywhere database via PuTTY, and I don't think it's working.

I'm following the instructions on this page: https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere/#using-putty-on-windows

When I click 'Open' I enter my login credentials to PythonAnywhere and connect, but when I enter the line

mysql -h 127.0.0.1 -u username -p

With my PythonAnywhere username in place of username, I get the message listed in the message title.

When I switch 127.0.0.1 with localhost I get the following message instead:

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

I was on codementor trying to troubleshoot my connection issues via PuTTY and he thought this was strange, and indicative that there might be some sort of security setting that needed to be changed on my account.

Does the fact that I can't run this command in the PuTTY terminal after I've opened a connection signify something unusual about my account?

Are you running the

mysql -h 127.0.0.1 -u username -p

command in the PuTTY console that's running commands on PythonAnywhere? You're meant to run it in a command prompt on your local machine.

@giles -- thank you.

Two questions:

Is this command REQUIRED for getting an SSH connection through PuTTY up and running? Because what I'm really trying to troubleshoot is why that doesn't work.

When I run this on my local machine is says mysql isn't a recognized command. Do you have a suggestion for getting around this? It looks like you need to set an environment variable, but I'm not sure how to do this.

Thank you.

Nevermind, I figured that out, the mysql command works now.

However, I'm receiving this error:

ERROR 1045 (28000): Access denied for user 'jonathanbechtel'@'localhost' (using password: YES)

This is what happens when I use the mysql -h 127.0.0.1 -u jonathanbechtel -p command.

Perhaps it's worth taking a step back -- what is the goal of what you're trying to do here? Are you trying to access the contents of your MySQL database via a mysql command running on your local machine? Or are you trying to access the database using some local GUI app like MySQL workbench? Or do you want to access the database from code that you want to run on your local machine?

Thanks Giles.

What I want to do is connect Tableau to the database I have stored here at PythonAnywhere and use its contents to populate a dashboard in my Tableau account.

AFAIK PythonAnywhere only allows SSH connections when a database is being accessed remotely. Tableau doesn't handle SSH connections very gracefully, so in order to get my database into Tableau I have to open up an SSH Tunnel via PuTTY, and then connect Tableau locally via that.

So, ultimately, I want to log into Tableau, and enter my information on this screen: https://imgur.com/zS5Dvi2 and see my database tables in the left hand side of the connections pane so I can go to work on it.

However, for the last two weeks this has proven to be an intractable problem. I've been playing Q&A ping-pong on here, Stack Overflow, Tableau's forums and codementor trying to get a resolution, but I've basically gotten stuck in a repeating loop of error messages and people asking me to check with the other vendor on what their account settings might be.

But ultimately, I can't improve this basic process:

  1. I open up PuTTY
  2. I enter ssh.pythonanywhere.com as the Host Name with a Port Number of 22 and an SSH connection Type
  3. I go to Category --> SSH --> Tunnels
  4. in Destination I put jonathanbechtel.mysql.pythonanywhere-services.com:3306 with the options 'Local' and 'Auto' checked
  5. I put 3306 as the source port
  6. I hit 'Open' and then I follow the prompts on PuTTY to sign into my Python Anywhere account
  7. After that I leave the PuTTY terminal open and I open up Tableau
  8. I arrive at the image I linked to before
  9. At the Tableau screen I linked to: - in the 'Server' field I enter 127.0.0.1 (or localhost) - in the port field I enter 3306 - in the username field I enter my pythonanywhere username - in the password field I enter my database password

Going through all of this gives me the following error message:

[MySQL][ODBC 8.0(w) Driver]Access denied for user 'jonathanbechtel'@'localhost' (using password: YES) Invalid username or password.

I've checked my username and password and they work.

A few more items:

  • I have a jupyter notebook that I use to connect to this database through an SSH Tunnel and it works, using the same password and username that I use in Tableau
  • I have my firewall turned off
  • I don't have any local databases running in the background when I do this

The questions I ask on various sites now are scatter shot, but that's because I've tried to ask more comprehensive questions on Tableau here, on SO here, and on these forums here, but there's been no resolution. So I try to find different angles to use towards the problem to see what comes up, and then ask questions based off of that in hopes of arriving at the answer in a more circumspect way. So collectively my activity on various Q&A sites probably looks unfocused, but that's only because the more obvious approaches have been exhausted.

......and I got it. Okay. Problem solved. It wasn't PuTTY or Python anywhere. It turns out Tableau, when bridging to a data source such as this........requires you to specify a separate port # besides 3306, even if you don't have an existing MySQL db running on localhost:

So I made up a new destination port # and that solved it. Whew!

Sorry for being a pain :(

Whew! Glad to hear you worked it out in the end, that must have been a tough one to debug.