Get the App
SLTechnology News&Howtos  ›  Database  › 

ERROR 1045 (28000): Access denied for user 'root'@

Shulou Source: shulou.com Published: 2022-06-01 09:56:28 09月30日 Update

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor

Error description: after adding a user to Mysql, there may be an error that prompts ERROR 1045 (28000): Access denied for user when logging in. Delete the value NULL in user.user, or update the NULL to test 1) delete from user where user is NULL 2) update user set user='test' where user is NULL. Unexpected situation: if the above method does not work and there are still empty users, you can use graphical user client to delete.

After reinstalling CentOS, I found that Mysql has not been easy to use.

# mysqladmin create dbname command always returns mysqladmin: connect to server at 'localhost' failed

# mysql-u root@localhost

> create database dbname

Also return error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

# mysql-u root-p

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Use the method described online to change the password of a root user:

# mysqladmin-uroot-p password' newpassword'

Enter password:

Mysqladmin: connect to server at 'localhost' failed

Error: 'Access denied for user' root'@'localhost' (using password: YES)'

Now I have finally found the solution, as follows (please test method 3 first, thank you! ):

Method 1:

# / etc/init.d/mysql stop

# mysqld_safe-user=mysql-skip-grant-tables-skip-networking &

# mysql-u root mysql

Mysql > UPDATE user SET Password=PASSWORD ('newpassword') where USER='root'

Mysql > FLUSH PRIVILEGES

Mysql > quit

# / etc/init.d/mysql restart

# mysql-uroot-p

Enter password:

Mysql >

Method 2:

Directly use the username and password provided in the [client] section of the / etc/mysql/debian.cnf file:

# mysql-udebian-sys-maint-p

Enter password:

Mysql > UPDATE user SET Password=PASSWORD ('newpassword') where USER='root'

Mysql > FLUSH PRIVILEGES

Mysql > quit

# mysql-uroot-p

Enter password:

Mysql >

Method 3:

I have not tested this method, because my root user's default password has been changed by me. That one is free to test it and tell me the result. Thank you!

# mysql-uroot-p

Enter password:

Final note: don't forget to turn off the firewall, lest the external network cannot access the database port of the host.

At this point, the problem that has been confused for a long time has been solved!

If you reprint it, please indicate the source of Weili blog: http://www.wangweilin.name/rj_446.html

Tags: Method user password error test confusion accident bad median host provenance blog command graphics situation effect data database file user name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia MariaDB Linux Apple