MySQL Connection Errors

From Free Hosting Wiki
Revision as of 00:22, 22 June 2011 by Misson (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Jump to: navigation, search

This article describes what to do if your code attempts but fails to connect to the X10 MySQL server. Usually, this means you get an error such as "SQLSTATE[28000] [1045] Access denied for user 'user_name'@'' (using password: YES)". Basically, the solution amounts to checking the MySQL information.

MySQL authentication is based on three pieces of information which need to match what's on the server, so an "access denied" error has four potential causes:

  • Wrong username.
  • Wrong password.
  • The client computer isn't allowed.
  • Wrong server.



When you create a user using cPanel, your cPanel name and an underscore are prepended to it to create the database username. For example, if your cPanel name is "foo" and you create the user "bar", the actual database username is "foo_bar". If you leave off the prefix, the connection will fail.


Double check that your code uses the correct password for the user. If it doesn't give a password when connecting, the connection will fail. If you see "(using password: NO)" in the error message, this is the cause.

You can change the password for an existing user by following the steps to create a user but give the name (sans prefix) of an existing user. Try temporarily changing the password to something that only uses digits (except 0 and 1) and lower case letters (except l). Make sure you change it to something more complex afterwards.


As per the MySQL information, the host should be "localhost". Note that you don't need to specify the port.

Client computer

MySQL accounts are identified by the database username and the hostname of the client computer combined. If there's no entry for both together, the connection will fail. Normally, your X10 host should have been given access to the MySQL server when your account was created or moved, but sometimes this needs to be configured manually, which you can do from within cPanel:

  1. Note the server name in the error message. In the example error at of the top of this article it's "".
  2. Sign into cPanel.
  3. Note your server name in the "Stats" panel on the left.
  4. In the "Databases" panel, click "Remote MySQL"
  5. Make sure you see something like the following entries. Italics indicate a value that you may need to customize. If any are missing, add them.
    • 10.33.248.% (internal IP block for
    • 10.33.249.% (internal IP block for
    • (internal IP for; you'll likely need something different)
    • 192.168.1.%

The first two entries you see may vary from the above, and the third will likely be different. You can get the correct value for the first by running a DNS query for "" to get its IP address, then substituting "%" for the last quad. Get the correct value for the second by doing the same for the host name from the error message, or by substituting your server name from step 2 for host. The correct value for the third is the same as for the second, but without substituting '%'.

Not all of the entries may be necessary, but neither should they cause problems. From my account, I also see a "", but I suspect this is an old IP for one of the hosts I've been on.

Personal tools