I have hosting provided by eleven 2 and I just created a new MySQL user and gave it access to every action listed.
I\'m getting the following error
Usually the password field is not required unless you set a password for mysql.
you can use mysql_connect("hostname","username","")
But if you have set the password for your mysql then you have to write password while connecting. And if still it doesn't working , then might be you have to look at your username and password.
I had same issue, I was trying to connect between two different Web Servers. If I use my PHP script on same server the connection will establish but if I use the same script file from other Web Server (Web Hosting) it gave this error.
I solved it by allowing access to MySQL Server (Remote MySQL) by providing the IP address from where I used to connect.
it is also worth noting that I used Domain but Domain Name did not work for me. Also both CPanel and itself MySQL users could connect to MySQL Server. Hope its helpful for you also.
What is your sql server ? some companies change the server name from local host to something else to security purpose - Well but if its saying access denied for user that is may be your are connecting to wrong database ? that is
mysql_select_db(SQL_DB)
Are you sure you are using the correct database name ? and you are able to log into your SQL account with same username and password ? well if the problem still persist trying using the root account of SQL the super admin hope you are on your local computer or have a dedicated server.
Why don't you try using them in this form -
$con = mysql_connect("host name","username","password");
$db = mysql_select_db("database name",$con);
I stumbled upon this connection info about Cpanel http://www.inmotionhosting.com/support/community-support/databases/1045-access-denied-for-user-mysql-error
Your cPanel username and password can be used to connect to your databases (as well as your cPanel). If you're connecting to your database using your cPanel username and password, you can reset your cPanel password to ensure you are using the correct username and password.
If you setup a MySQL username and password specifically for accessing a database, you'll want to ensure you are using the correct username in your php scripts. For example, MySQL usernames are always in this format:
cpanel-username_mysql-username
If your cPanel username is userna5 and you created a database username of dbuser1, then the actual database username would be:
userna5_dbuser1
Temporarily, I'd suggest changing your databse password to that of your Cpanel account just to eliminate any doubts.