MySQL Connection Errors

From Free Hosting Wiki
Revision as of 03:11, 1 December 2011 by Skizzerz (Talk | contribs)


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'@'localhost' (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.

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.

Personal tools
Namespaces

Variants
Actions