Home > Database > Mysql Tutorial > How to Fix MySQL Error 1044: Access Denied for User?

How to Fix MySQL Error 1044: Access Denied for User?

Susan Sarandon
Release: 2024-12-02 13:57:09
Original
640 people have browsed it

How to Fix MySQL Error 1044: Access Denied for User?

Resolving Error 1044 on MySQL: Access Denied for User

In MySQL, you may encounter the error "ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'db'" while attempting to execute queries. This error indicates a lack of proper user privileges.

Identifying User Privileges

To check the current user's privileges, execute the command:

SHOW GRANTS
Copy after login

If you see the following output:

+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
Copy after login

It means you have only USAGE privileges on all databases, but no table-level privileges or the ability to create users.

Creating a New User

To create a new user with the necessary privileges, you will need to be logged in as a user with the CREATE USER privilege. Since you do not have a user with such privileges, you need to exit the MySQL command-line and log in as the root user:

mysql -u root -p
Copy after login

Enter the root password when prompted.

Create a New User with Privileges

Once you are logged in as root, execute the following command to create a new user called 'parsa':

CREATE USER 'parsa'@'localhost' IDENTIFIED BY 'parsa'
Copy after login

Granting Table-Level Privileges

Next, grant the newly created user the necessary table-level privileges. For example, to grant all privileges on the 'test' database:

GRANT ALL PRIVILEGES ON test.* TO 'parsa'@'localhost'
Copy after login

Exiting MySQL and Re-establishing Connection

After creating the new user and granting privileges, exit MySQL by typing:

exit
Copy after login

Re-establish a connection with the newly created user:

mysql -u parsa -p
Copy after login

The above is the detailed content of How to Fix MySQL Error 1044: Access Denied for User?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template