InMotion Hosting Support Center

1045 access denied for user - MySQL error

Category: Databases

2012-05-12 5:16 pm EST

Hits: 42,072
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 file.

Is this what I need to do to fix this problem, and if so, how do I access the 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


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.

<strong>#1045 - Access denied for user</strong>

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 <a href='' target='_blank'>reset your cPanel password</a> 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:


If your cPanel username is userna5 and you created a database username of dbuser1, then the actual database username would be:


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 <a href='' target='_blank'>MySQL database wizard</a> within your cPanel. If you already have the database created however, you can create a new user and assign it to your database by <a href='' target='_blank'>logging into your cPanel</a> 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.

- 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.
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)
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.

<a href="" target="_blank">How to create and attach a database user in cPanel</a>

Best Regards,
James R
5,889 Points
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","********");
die("Could not connot server." . mysql_error());
$db_select = mysql_selectdb("mahabudd_db",$connection);
die("Could not find database." . mysql_error());
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

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 ( for the hostname.

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

31,633 Points
2013-07-03 1:30 pm EST
Like this Question?

Forum Login

You are NOT logged in. You can still browse our Support Center.

To participate within our Community Support Forum:

Need more Help?

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:
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!