1045 access denied for user - MySQL error

Category: Databases

jdgrimes
Asked:
2012-05-12 5:16 pm EST

Hits: 9,856
I am trying to run a query on one of my databases, and I am getting the following error: "#1045 - Access denied for user '[My username]'@'localhost' (using password: YES)". I think that in order to fix this I need to reset my password in the config.inc.php file.

Is this what I need to do to fix this problem, and if so, how do I access the config.inc.php file???

Thank you in advance.

You must login before you can ask a follow up question.

You must login before you can submit an answer.

Best answer chosen by User

0

BradM
Staff
5,399 Points
2012-05-14 9:26 am EST
Hi jdgrimes,

If your account is on a shared server (which it appears yours is), you actually do not have access to update any settings within phpMyAdmin. This is because in a shared server, those changes you would make would affect all other users in the shared server.

#1045 - Access denied for user

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

When connecting to a database, you need to ensure that:
1. You've created a database
2. You've created a database username
3. You've assigned that user with privileges to your database

All three of these steps can be done easily within the MySQL database wizard within your cPanel. If you already have the database created however, you can create a new user and assign it to your database by logging into your cPanel and clicking the MySQL Databases icon. From this screen, you can also reset your MySQL user's password.

I hope this helps point you in the right direction. If you need further help, feel free to post a comment at the bottom of this page with more details.

Thanks!
- Brad

You must login before you can post a comment about this answer.

Hi BradM,
I have login account of cPanel ie. [User: bruth, Pass: robot].
Inside cPanel By using phpMyAdmin I created
1. Database [Name ie. bruth_db]
2. User [Username: brad, Password: pass] and set all previllage to database [bruth_db].
In my PHP i have coded like this:
$connection = mysql_connect("localhost","brad","pass");

But every time i find this error message in my page.
Access denied for user 'mahabudd'@'localhost' (using password: YES)

Is there any technically fault or missing? I am tiered tracing it. It is bouncing me.
SudeepSamson
9 Points
2013-07-02 7:23 am EST
Sorry. Once again error message. (actually user name wrong typed).
Access denied for user 'brad'@'localhost' (using password: YES)
SudeepSamson
9 Points
2013-07-02 7:26 am EST
Hello SudeepSamson!

Make sure you are using the database username and password you used when you set up the database user and password. See the article below for more information on that.

How to create and attach a database user in cPanel

Best Regards,
James R
jamesr
5,889 Points
Staff
2013-07-02 10:13 am EST
Again this question to jamesr
I revised several this but no good luck again.

My database name: mahabudd_db
User with every previllage to database: mahabudd_user

----- coding like this

$connection = mysql_connect("localhost","mahabudd_user","********");
if(!$connection)
{
die("Could not connot server." . mysql_error());
}
else
{
$db_select = mysql_selectdb("mahabudd_db",$connection);
if(!$db_select)
{
die("Could not find database." . mysql_error());
}
else
{
echo "Selected";
}
}

------ Error display

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'mahabudd_user'@'localhost' (using password: YES) in /home/mahabudd/public_html/dat.php on line 4
Could not connot server.Access denied for user 'mahabudd_user'@'localhost' (using password: YES)

------------------- IN cPANEL HELP I FOUND
Mysql gives error of access denied for root@localhost?
Make sure root pass is in /root/.my.cnf.
This is usually the first root pass the box was given once cpanel is installed. If it still does not work, you will need to reset the mysqld root pass. To do so:
Stop the mysqld.
Usually /etc/rc.d/init.d/mysql stop
Stop chkservd to keep it from interfering with mysqld
/etc/rc.d/init.d/chkservd stop
Start mysqld without the grant tables
mysqld --skip-grant-tables -u mysql &
Change the pass.
mysql -u root mysql UPDATE user SET Password=PASSWORD('new_password') WHERE user='root'; FLUSH PRIVILEGES;
Now you just killall -9 mysqld and start it up normally with it's safe_mysqld script.

I COULD NOT UNDERSTAND THAT. May be this is what the solution goes for??

Thanks and Regards.
Sudeep Samson



SudeepSamson
9 Points
2013-07-03 6:59 am EST
Hello SudeepSamson,

According to to your error (Access denied for user 'mahabudd_user'@'localhost'), this username (mahabudd_user) is incorrect, or has not been added to the database, your password is incorrect, or your hostname is wrong.

At this point, I recommend reading this guide, and making sure you have completed the steps in the section titled Assign the user to one or more databases.

If it has been completed successfully, and is still not connecting successfully, then try resetting the database password.

If the database is on the same server as your website, you should use localhost as the hostname.

If you are connecting to a remote database, you will have to add the IP address of your website's server to the firewall of the server hosting the database, and use the domain name (example.com) for the hostname.

If you have any further questions, feel free to post them below.
Thank you,

-John-Paul
johnpaulb-imhs1
9,684 Points
Staff
2013-07-03 1:30 pm EST
Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!