skip to Main Content

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


  1. PDO Exception: SQLSTATE[HY000] [1045] Access denied for user ‘
    graphgr1_mhazaa’@’localhost’ (using password: YES)

    To connect from a script in your cPanel account to a database also in your cPanel account you need to just

    1. Create Database
    2. Create User for it
    3. Give necessary grants to the User

    To connect locally, from your own computer to a cPanel hosted database you need to:

    1. Have a Database and an User assigned to it.
    2. Allow your local computer’s IP in cPanel’s Remote MySQL tool

    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

    mysql -u YOUR_USER -p YOUR_DATABASE ## MySQL added User connection, sees only databases it has access to
    mysql -u cPanel_USER -p             ## cPanel User connection, sees all databases added in your cPanel account
    
    Login or Signup to reply.
  2. 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

    chmod 400 filename
    

    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

    ssh -i id_rsa -L 3307:yourcpanel.hosted.xxx:3306 yourcpanelusername@your cpanel.hosted.xxx -N
    

    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

    db = pymysql.connect(host=DB_HOST, user=DB_USER, passwd=DB_PWD, db=DB_NAME,  port=DB_PORT)  
    

    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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search