Mysql error 42000 access denied

‘SQLSTATE 42000 1044 access denied for user’ – 5 steps to fix this error

I developed my website, but many pages that access the database throw the error ‘SQLSTATE 42000 1044 access denied for user’. Can you help!

That was a recent support ticket received at our Outsourced Technical Support department where we resolve support queries for web hosts.

Website owners often face this error due to insufficient database privileges, typo errors in username/password, and more.

So, what’s the solution here? Well, the solution varies depending on the reason for this error.

Today, let’s discuss the top 5 reasons for this error and how our Dedicated Support Engineers fix it.

‘SQLSTATE 42000 1044 access denied for user’ – What this means?

Before we move on to the reasons for this error, let’s first get an idea of this error.

Website owners usually face this error when MySQL disallow access to a database.

For instance, the complete error message looks like this:

This error shows that MySQL denies the user ‘test’@’localhost’ access to the ‘test_database’ database.

[You don’t have to be a MySQL expert to keep your websites online. Our MySQL admins are available round the clock.]

‘SQLSTATE 42000 1044 access denied for user’ – Causes and Fixes

In our experience managing servers, let’s see the main causes of this error and how our Dedicated Support Engineers fix it.

1) Incorrect details in website configuration file

This is the most common reason for the error ‘SQLSTATE 42000 1044 access denied for user‘.

Database driven websites like WordPress, Drupal, etc. use the details in the website configuration file to connect to the database and fetch data.

So, typo errors in the database name, database username, password, hostname, database port, etc. can lead to errors.

How we fix?

In such cases, our Hosting Engineers recover the database details, and correct them in the website configuration files.

And, if we can’t recover the password, we reset it and update it in the website configuration file.

Also, we ensure that the new password adheres to the MySQL password policy.

For example, in cPanel servers, we reset the database user password from

cPanel > Databases > MySQL databases > MySQL users > Current users.

MySQL databases option in cPanel

2) Database user doesn’t exist

Similarly, this error occurs when the user trying to access the database doesn’t exist on the MySQL server.

Also, this error can sometimes occur when the database user isn’t properly mapped to the database.

How we fix?

In such cases, our Support Engineers check whether the database user exists in the MySQL user table.

If not, we check the user’s requirement and if valid, we create a user with that username.

In addition to that, we assign this user to the corresponding database.

For instance, in cPanel servers, we map the database user to the database from cPanel > Databases > MySQL Databases > MySQL users > Add User to Database.

3) Insufficient database user permissions

Sometimes, database users don’t have the right privileges to access the database.

In such cases, website owners see this error ‘SQLSTATE 42000 1044 access denied for user

READ  System web server error
How we fix?

Here, our Hosting Engineers grant the user, proper privileges over the database to correct this problem.

For example, in cPanel servers, we assign access privileges to a user from here:

cPanel > MySQL databases > Current databases >Privileged users > Click on the database user

How to set database user privileges in cPanel

On plain servers, we assign the user privileges from command line.

For example, we use the below command to grant all privileges to the user, ‘test’@’localhost to the database ‘test_database’.

And, in-order for the changes to reflect, and the privileges to be saved, we use the below command.

[Struggling with database user permissions and privileges. Our MySQL experts are here for your help.]

4) Existence of anonymous users

Website owners face this error when there exist anonymous users like ‘ ‘@localhost or ‘ ‘ @

That is, when a client connects to the database, MySQL looks through the rows in the user table in a sorted way.

And, it uses the first row that matches the hostname and username.

So, here the anonymous user precedes all other users when connecting from localhost.

How we fix?

Our Support Engineers check the MySQL user table and remove the anonymous user.

For instance, we use the below command to remove the anonymous user from MySQL user table.

5) Missing PDO module

Website developers see this error when trying to access the database using PDO.

And, this often occurs due to the missing PDO module.

Most web hosts enable PDO module by default, but some web hosts may disable this module.

How we fix?

In such cases, our Hosting Engineers enable the PDO module on the server.

On cPanel servers, we enable it exclusively for the domain via the PHP Selector option.

PHP Selector in cPanel

[If you suspect missing PHP modules in your server. Our Support Experts can fix it for you within minutes.]


In short, ‘SQLSTATE 42000 1044 access denied for user’ error can occur due to insufficient user rights, typo in username/password, and more. Today, we’ve discussed the top 5 reasons for this error and how our Dedicated Support Engineers fix it.


Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.


thank you, my problem was Insufficient database user permissions, I Privileged my User to the database and solved my problem

Thanks. This step-by-step guide helped me. It turned out, my user privileges was not granted.


ERROR 1044 (42000): Access denied for user »@’localhost’ to database ‘db’

I want to begin writing queries in MySQL.

show grants shows:

I do not have any user-id but when I want to make a user I don’t have privilleges, also I don’t know how to make privileges when even I don’t have one user!

I tried to sign in as root:

12 Answers 12

No, you should run mysql -u root -p in bash, not at the MySQL command-line. If you are in mysql, you can exit by typing exit.

You may need to set up a root account for your MySQL database:

In the terminal type:

And then to invoke the MySQL client:

I was brought here by a different problem. Whenever I tried to login, i got that message because instead of authenticating correctly I logged in as anonymous user. The solution to my problem was:

To see which user you are, and whose permissions you have:

To delete the pesky anonymous user:

This is something to do with user permissions. Giving proper grants will solve this issue.

Step [1]: Open terminal and run this command

Output [1]: This should give you mysql prompt shown below

  • hostname can be IP address, localhost,
  • In database_name / table_name , * means all databases
  • In hostname , to specify all hosts use ‘%’

Step [3]: Get out of current mysql prompt by either entering quit / exit command or press Ctrl+D .

READ  Lenovo g700 прошивка мультиконтроллера

Step [4]: Login to your new user

Step [5]: Create the database

You might want to try the full login command:

where host would be .

Do this just to make sure cooperation exists.

Using mysql -u root -p allows me to do a a lot of database searching, but refuses any database creation due to a path setting.

If you are in a MySQL shell, exit it by typing exit, which will return you to the command prompt.

Now start MySQL by using exactly the following command:

If your username is something other than root, replace ‘root’ in the above command with your username:

It will then ask you the MySQL account/password, and your MySQL won’t show any access privilege issue then on.

First, if you are unfamiliar with the command line, try using phpmyadmin from your webbrowser. This will make sure you actually have a mysql database created and a username.

This is how you connect from the command line (bash):

connect mysql with sudo & gives permission for the necessary user using,

@Nickparsa … you have 2 issues:

1). mysql -uroot -p should be typed in bash (also known as your terminal) not in MySQL command-line. You fix this error by typing

in your MySQL command-line. Now you are back in your bash/terminal command-line.

2). You have a syntax error:

the semicolon in front of -p needs to go. The correct syntax is:

type the correct syntax in your bash commandline. Enter a password if you have one set up; else just hit the enter button. You should get a response that is similar to this:


Access denied for user ‘root’@’%’

I used to access the root user in MySQL just fine. But recently, I am no longer able to.

I am able to login fine :

Here is the mysql status after login :

But when I want to do any action, such as :

I understand % is used to signify any host , but my status clearly states localhost. Does somebody have an idea of what might be going on?

5 Answers 5

I think you have anonymous users

Try running this:

This will show what anonymous users exist. Most likely, you will see a line with a blank user, host % , and a blank password as shown below:

So, how did you login? Run this query:

What does this tell you?

  • USER() reports how you attempted to authenticate in MySQL
  • CURRENT_USER() reports how you were allowed to authenticate in MySQL

The second function CURRENT_USER() reveals how which anonymous user was used to log in.

What privileges did you have when you logged in?

This will unveil what privileges you had at the time you logged in. The fact that you were blocked from creating a database shows you were not root but some lower-privileged user.

Please clean up your user grants.

As for resetting the root password, please do the following:

I know what you did.

You will probably notice it returns a ‘N’ for Grant_priv. So do this:

And walla! Hope that helps.

After you enter as the root user check your privileges:

After checking your privileges you can try to give another user all the privileges, or you can try to give the root user all privileges again:

If your root user doesn’t have privileges you can try to restore them, so:

Stop the mysqld server

Restart the server this way mysqld_safe —skip-grant-table

Restore root privileges with:

Your privileges may be be reduced?

Also, you can try to create another account with root privileges.

And delete root user, and re-create with specified privileges.

C. — LINUX (Make file with query who create, a new user with full root privileges)

C. — Windows (Make file with query who create, a new user with full root privilegles)

Query: (Create root user)

Check if you are running the import query against information_schema db, I fell for that for a while because I was using a new MysQL client and didn’t realize that the query was trying to create tables in information_schema db (since the new db to be created didn’t exist when running the query, the connection fell back to the first db in the server).

READ  Net framework 30319 error

I tried every single answer here and took me nowhere as root access was used and privileges seemed right.


Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.1.14.43159

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.


Access denied; you need (at least one of) the SUPER privilege(s) for this operation

Part of AWS Collective

So I try to import sql file into rds (1G MEM, 1 CPU). The sql file is like 1.4G

mysql -h -u user -ppass —max-allowed-packet=33554432 db another_user is not existed in rds, so I do:

17 Answers 17

Either remove the DEFINER=.. statement from your sqldump file, or replace the user values with CURRENT_USER .

The MySQL server provided by RDS does not allow a DEFINER syntax for another user (in my experience).

You can use a sed script to remove them from the file:

If your dump file doesn’t have DEFINER , make sure these lines below are also removed if they’re there, or commented-out with — :

Note that the comment characters are «dash dash space» including the space.

A better solution is to stop these lines from being written to the dump file at all by including the option —set-gtid-purged=OFF on your mysqldump command.

Another useful trick is to invoke mysqldump with the option —set-gtid-purged=OFF which does not write the following lines to the output file:

not sure about the DEFINER one.

When we create a new RDS DB instance, the default master user is not the root user. But only gets certain privileges for that DB instance. This permission does not include SET permission. Now if your default master user tries to execute mysql SET commands, then you will face this error: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation

Solution 1

Comment out or remove these lines

Solution 2

You can also ignore the errors by using the -f option to load the rest of the dump file.

Just a MacOS extra update for hjpotter92 answer.

To make sed recognize the pattern in MacOS, you’ll have to add a backslash before the = sign, like this:

Problem: You’re trying to import data (using mysqldump file) to your mysql database ,but it seems you don’t have permission to perform that operation.

Solution: Assuming you data is migrated ,seeded and updated in your mysql database, take snapshot using mysqldump and export it to file

GTID — A global transaction identifier (GTID) is a unique identifier created and associated with each transaction committed on the server of origin (master). This identifier is unique not only to the server on which it originated, but is unique across all servers in a given replication setup. There is a 1-to-1 mapping between all transactions and all GTIDs.

—set-gtid-purged=OFF SET @@GLOBAL.gtid_purged is not added to the output, and SET @@SESSION.sql_log_bin=0 is not added to the output. For a server where GTIDs are not in use, use this option or AUTO. Only use this option for a server where GTIDs are in use if you are sure that the required GTID set is already present in gtid_purged on the target server and should not be changed, or if you plan to identify and add any missing GTIDs manually.

Afterwards connect to your mysql with user root ,give permissions , flush them ,and verify that your user privileges were updated correctly.

now reload the data and the operation should be permitted.