Error 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) is a common error message that occurs when attempting to log in to a MySQL or MariaDB server with the root user and an incorrect or empty password. This error can also occur when trying to connect to the server using a different user account with incorrect login credentials.
Here are some common causes of this error:
-
Incorrect login credentials: Double-check that the username and password being used to connect to the server are correct. If the password is lost or forgotten, it can be reset using the mysqladmin command.
-
User account is locked: This can happen if an incorrect password is entered multiple times. To unlock the account, you can use the following command:
mysql> UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
mysql> FLUSH PRIVILEGES;
-
Firewall blocks the connection: MySQL uses port 3306 to communicate, so make sure that the firewall on the server is configured to allow connections on that port.
-
mysql.user table is corrupt: In some cases, the mysql.user table may become corrupt and prevent the root user from logging in. You can repair the table with the following command:
mysql> myisamchk -r /path/to/mysql/data/mysql/user.MYI
-
mysql service has not been started: make sure the mysql service is running on the system.
-
try to connect with –skip-grant-tables option:
mysqld --skip-grant-tables
- try to connect with –skip-password option:
mysql -u root --skip-password
To resolve the Error 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) error, you will need to troubleshoot the specific cause of the issue on your server. Once you have identified the problem, you can take the appropriate steps to fix it and regain access to your MySQL or MariaDB server.
It is important to note that the above solutions are for the localhost, you may have to change the hostname or IP address if you are trying to connect from a different machine.
- Resetting the root password: If you've lost or forgotten the root password for your MySQL or MariaDB server, you can reset it by stopping the MySQL server, starting it in safe mode with the –skip-grant-tables option, and then using the UPDATE statement to set a new password. Here's an example of how to reset the root password:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET authentication_string=PASSWORD("new_password") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit;
sudo service mysql start
- Creating new user accounts: You can create new user accounts for your MySQL or MariaDB server by using the CREATE USER statement. Here's an example of how to create a new user named "myuser" with the password "mypassword":
mysql> CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
- Granting permissions to a user: Once you've created a new user, you'll need to grant that user the necessary permissions to access the databases and tables on your server. You can use the GRANT statement to grant permissions to a user. Here's an example of how to grant all permissions to the "myuser" account on the "mydb" database:
mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
- Revoking permissions from a user: If you need to revoke permissions from a user, you can use the REVOKE statement. Here's an example of how to revoke all permissions from the "myuser" account on the "mydb" database:
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'myuser'@'localhost';
-
Backup and restore: Backing up and restoring your MySQL or MariaDB server is an important task to ensure your data is safe and secure. There are several ways to backup and restore your server, including using mysqldump, and logical backup and restore.
-
Secure your mysql server: To secure your mysql server you should follow some best practices, such as:
- Always use the latest version of MySQL
- Use a strong password for the root account
- Remove anonymous users
- Remove test database and access to them
- Remove remote root login
- Remove the ability to log in as the root user from anywhere other than the localhost
- Use firewall to block all incoming connections to MySQL port except from trusted IP
- Use SSL to encrypt all connections
These are just a few examples of the many tasks that you can perform with MySQL or MariaDB. To learn more about these and other topics, you can refer to the official MySQL or MariaDB documentation.
Popular questions
-
What is error 1045 (28000) in MySQL or MariaDB?
- Error 1045 (28000) is an error message that occurs when attempting to log in to a MySQL or MariaDB server with the root user and an incorrect or empty password.
-
What are some common causes of error 1045 (28000)?
- Incorrect login credentials, user account is locked, firewall blocks the connection, mysql.user table is corrupt, mysql service has not been started.
-
How can I reset the root password in MySQL or MariaDB?
- You can reset the root password by stopping the MySQL server, starting it in safe mode with the –skip-grant-tables option, and then using the UPDATE statement to set a new password.
-
How can I create new user accounts in MySQL or MariaDB?
- You can create new user accounts by using the CREATE USER statement.
-
How can I secure my MySQL or MariaDB server?
- To secure your MySQL or MariaDB server, you should use the latest version of MySQL, use a strong password for the root account, remove anonymous users, remove test databases and access to them, remove remote root login, remove the ability to log in as the root user from anywhere other than the localhost, use firewall to block all incoming connections to MySQL port except from trusted IP, use SSL to encrypt all connections.
Tag
Authentication.