MySQL Connection Errors

From Free Hosting Wiki
(Difference between revisions)
Jump to: navigation, search
[checked revision][checked revision]
(Initial article.)
 
m (Username)
Line 8: Line 8:
  
 
== Username ==
 
== Username ==
When you [[How to Create a MySQL Database and User|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.
+
When you [[How to Create a MySQL Database and User|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 out the prefix, the connection will fail.
  
 
== Password ==
 
== Password ==

Revision as of 16:11, 21 October 2011

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'@'int.host.x10hosting.com' (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.

Contents

Username

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 out the prefix, the connection will fail.

Password

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.

Host

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 "int.host.x10hosting.com".
  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 int.vital.x10hosting.com)
    • 10.33.249.% (internal IP block for int.host.x10hosting.com)
    • 10.33.249.2 (internal IP for int.host.x10hosting.com; you'll likely need something different)
    • 192.168.1.%
    • int.host.x10hosting.com
    • int.mysql.x10hosting.com

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 "int.vital.x10hosting.com" 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 "69.162.70.130", but I suspect this is an old IP for one of the hosts I've been on.

Personal tools
Namespaces

Variants
Actions