This is been driving me nuts for days. I created a database in cPanel, with a user and enabled all the privileges checkboxes.
Now whenever I try accessing my database, it doesn’t work and the errorlog show:
PDO Exception: SQLSTATE[HY000] [1045] Access denied for user ‘
graphgr1_mhazaa’@’localhost’ (using password: YES)
I tried acessing the database locally from the command line
mysql -u myUsername -pMyPassword -h remoteHostIP -D databaseName
and it showed:
ERROR 1045 (28000): Access denied for user ‘username’@’c-174-53-152-193.hsd1.mn.comcast.net’ (using password: YES)
I even tried to access the database as root
mysql.exe -u root -h remoteHostIp -D databaseName
Same message. I’m pretty sure I got all the spelling/names right, and tried it on different computers too. So any ideas what the problem might be?
2
Answers
To connect from a script in your cPanel account to a database also in your cPanel account you need to just
To connect locally, from your own computer to a cPanel hosted database you need to:
The way that cPanel hosted MySQL works is that it requires all MySQL connections to be from authorized IP addresses.
What allows you to connect your scripts from your cPanel account to your cPanel hosted databases is that the server’s IP address is already present in the Remote MySQL tool.
Using SSH you can connect just by using
I have a slightly different take on this.
I managed to access my MySql database using Sequel Pro on my Mac laptop by generating a SSH key in cpanel and copying this (the id_rsa file) onto my Mac.
It wont then work unless you change the permission on this file to 400
However, once Sequel Pro was working I then tried to read my database via python using pymsql.
This gave rise to no end of problems and threw several variants of the error under discussion.
After an immense amount of fiddling about with mysql in the terminal window I gave up and turned to a local UNIX guru who came up with the following solution.
In the terminal type
For more info search for ‘ssh port forward only no shell’
As far as I understand it, it opens a local port number 3307 on the Mac and connects to cpanel on port 3306 using the id_rsa key and disallows commands. Once this up and running…
In your python code use some variant on this
where
DB_HOST = ‘localhost’, DB_USER = your cpanel database username, DB_PWD = your database password, DB_NAME = name of your cpanel database, DB_PORT = 3307