Forums

MySQL SSH tunnel acess denied

I'm facing exactly the same problem here: https://www.pythonanywhere.com/forums/topic/27243/

I'm not very experienced with MySQL, but I can connect to ssh, it opens a remote console, but I can't connect to the database, and I typed the password correctly. It shows the same error even if the SSH tunnel is activated.

NOTE: forgiveness for any grammatical error, I'm using an automatic translator

should also add the option to delete a post

What's the code that you're using?

DATABASES = { "default": { "ENGINE": "django.db.backends.mysql", "NAME": "adpaz$adpaz", "USER": "adpaz", "PASSWORD": #database passoword, "HOST": "127.0.0.1", "PORT": "3306", } }

and the exit is:

django.db.utils.OperationalError: (1045, "Access denied for user 'adpaz'@'localhost' (using password: YES)")

I typed the database password correctly.

DATABASES = { "default": { "ENGINE": "django.db.backends.mysql", "NAME": "adpaz$adpaz", "USER": "adpaz", "PASSWORD": #database password, "HOST": "127.0.0.1", "PORT": "3306", } }

And the exit is:

django.db.utils.OperationalError: (1045, "Access denied for user 'adpaz'@'localhost' (using password: YES)")

I typed the database password correctly.

I want to access the database from my machine so I can test it during development

Do you want to run Django on your local machine but access MySQL server on PythonAnywhere? Take a look at https://stackoverflow.com/a/42101739/7959642 but it's hard to consider it a best practice.

That's exactly what I'm doing. But why is it not a recommended practice?

If you're just using it to test, it shouldn't be an issue. It's just that it's likely to be pretty slow.

As to your error. Are you sure that 3306 is the port that is the local end of the SSH tunnel? If you're running MySQL on your own machine, then it would be at port 3306, so you would be trying to connect to your local database server instead of the PythonAnywhere one through the tunnel.

What I did was as follows:

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

That was the way out:

 <<<<<<:>~ PythonAnywhere SSH. Help @ https://help.pythonanywhere.com/pages/SSHAccess
 adpaz@ssh.pythonanywhere.com's password: 
 bind [127.0.0.1]:3306: Address already in use
 17:13 $ ~

And this is code I use in Django:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "adpaz$adpaz",
        "USER": "adpaz",
        "PASSWORD": #database password,
        "HOST": "127.0.0.1",
        "PORT": "3306",
    }
}

This is the error it generates:

django.db.utils.OperationalError: (1045, "Access denied for user 'adpaz'@'localhost' (using password: YES)")

I also tried this:

mysql -h 127.0.0.1 -u adpaz -p

But this happens:

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

That is because your tunnel failed because you already have a MySQL server locally listening on port 3306 and then you're connecting to your local MySQL.

Change the first 3306 in the tunnel command to something else (like 3333) and then use that as the port that you try to connect to from Django or from the mysql client.

Worked, thank you!

Excellent, thanks for confirming!