Mysql cannot connect - Access denied (using password yes)
Asked Answered
Y

4

7

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

Warning: mysql_connect() [function.mysql-connect]: Access denied for user '(username is here, removed for posting)' (using password: YES) in /home/.../public_html/config.php on line 10

Here is my config file

//connection details have been removed for posting purposes

<?php

 define('SQL_SERVER',''); // Database Server
 define('SQL_USER',''); //  User
 define('SQL_PASS',''); //  Password
 define('SQL_DB',''); //  database



 mysql_connect(SQL_SERVER,SQL_USER,SQL_PASS) or die("Error: ".mysql_error()); // Connection to the server
 mysql_select_db(SQL_DB) or die("Error: ".mysql_error()); // Connecting to the database
?>

I tried to do the following as suggested by this post Access denied for user 'someuser'@'localhost' (using password: YES)

GRANT ALL PRIVILEGES ON databasename.* TO 'bookorama'@'%' IDENTIFIED BY 'yourpassword';
FLUSH PRIVILEGES;

But I got the following error "#1044 - Access denied for user". When I log into the CPanel and check out the database users, it shows the user that I tried to log in as, so I'm confused as to why it won't work.

EDIT - I got it to work. There was something wrong with the server. Contacted the host and they took care of it. Thanks for the replies.

Yves answered 28/9, 2012 at 2:59 Comment(17)
Are you sure you typed the password or username correctly ?Yser
Yes, I'm sure. I even set the password to something extremely simple (for testing purposes) and it won't connect.Yves
Serious question, when you did GRANT ALL, you did substitute your info for what's above, yeah?Quash
I tried your coding works fine for meYser
@Quash Yes, I made sure to swap for my info.Yves
@user1631889 this code runs fine on localhost, doesn't work on my live serverYves
did you try FLUSH PRIVILEGES?Quash
Maybe this can help you out :#5017005Yser
One thing I can say for sure - it's not the PHP code as this one is fine - it's something about the rights on your server, and / or the configuration - as it's for testpurposes only - reset the server reupload the files and try it out again with the superuser provided by your hosterTactics
@Ivan - I'm not too familiar with CPanel. Aside from granting users database access, where else can I change rights for the server?Yves
Another alternative is by using PHPMYADMINYser
I don't know CPanel as I use Plesk on my Server but it will be probably almost the same. Take a look for "Database-Server" in your CPanel - there should be some options for "matintaining" it - for plesk servers there usually is a runnning version of phpmyadmin - and with phpmyadmin you can easily change everything you needTactics
For CPANEL, Here is the picture how it looks like: blog.raptor.co.id/wp-content/uploads/2012/05/PhpMyAdmin.jpgYser
Oh, you mean restart mysql server? I can get into phpmyadmin with no problem.Yves
Are you trying to connect from your live web server to your live database server, or from your local web server to your live database server?Botel
@Botel I'm not sure exaction which connection you're talking about, but I logged into CPanel to create database users. From CPanel, I can access PHPMyAdmin and edit the databseYves
@user1443519: Can you provide more information on what your host did? I am having the exact same problem with a MySQL instance using cPanel.Orlene
D
8

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.

Desiraedesire answered 28/9, 2012 at 11:34 Comment(0)
C
3

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.

Calva answered 28/9, 2012 at 4:34 Comment(0)
A
1

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);
Abbreviation answered 28/9, 2012 at 4:6 Comment(1)
I'm going to delete the database and database users, and re-enter them. The account used to manage the database is different from the ones used to actually "log into" it. The one used to manage the database is actually the log in for the CPanel. There are database tools in CPanel that let you add and edit database users. Also, in CPanel, you can access PHPMyAdmin to edit the database. So, while I can create and edit the database and its users from the CPanel/PHPMyAdmin, that CPanel account is not the same as the ones created to log into the database from the config file.Yves
S
1

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.

Sugared answered 18/9, 2013 at 6:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.