Home >Database >Mysql Tutorial >How to Fix MySQL ERROR 1045 (28000): Access Denied for User 'root'@'localhost'?

How to Fix MySQL ERROR 1045 (28000): Access Denied for User 'root'@'localhost'?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-21 08:28:10658browse

How to Fix MySQL ERROR 1045 (28000): Access Denied for User 'root'@'localhost'?

How to Resolve "ERROR 1045 (28000)" in MySQL

During the installation of software on Ubuntu, an error message "ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)" may arise when attempting to import a database file using the following command:

mysql -uroot -proot <"Db.sql"

Cause of the Error:

This error occurs because the default root password for MySQL is empty (or blank), not root.

Solution:

To resolve the error and continue:

  1. Log in without a password:
mysql -u root
  1. Set a new root password:
mysqladmin -u root password [newpassword]
  1. Re-import the database file:

Navigate to the directory containing the database file and re-import it with the new password:

cd ~/Desktop/iPDC-v1.3.1/DBServer-1.1
mysql -uroot -p[newpassword] <"Db.sql"

Additional Tips:

  • For MySQL versions 5.7 and above, refer to the recommended solution by Lahiru in the provided link.
  • Consider setting up individual user accounts for database operations to ensure data integrity.

The above is the detailed content of How to Fix MySQL ERROR 1045 (28000): Access Denied for User 'root'@'localhost'?. For more information, please follow other related articles on the PHP Chinese website!

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