解决mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)

1 phenomenon

mysql -u root -p

错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)
2 linux系统:

In my-default.cnf profile or my.cnf

Add skip-grant-tables [mysqld] Under; because this method is ineffective, so we found the following method

For added security, MySQL5.7 randomly generate a password for the root user, the error log, with regard to the location of the error log, if the installation of RPM packages, the default is /var/log/mysqld.log.

So in / var / log / file is found mysqld.log

Use the command: vi Open

Enter the command mode

Find a random password generated

Enter: / temporary password

can be seen:

A temporary password is generated for root @ localhost: < temporary password you were looking for>
so we can use this password 'root' user of
mysql -u root -p Enter
To enter the password: <temporary password can fetch>
input : use mysql;
into the mysql is to modify the password
if the direct input: update user set authentication_string = password ( ' new password, for example: 123456') where user = ' root';
then: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
this means that you set a password '123456' does not comply with safety rules (1. must contain numbers, uppercase or lowercase letters, special characters;
2. the minimum length of 8)


Two global parameters must be modified
first, modify the value validate_password_policy parameters
set global validate_password_policy = 0;
so go apart from Rule 1, only the length limits
next to modify the parameters validate_password_length
MySQL> the SELECT @@ validate_password_length; # viewing parameter value
+ --- + -------------------------
| @@ validate_password_length |
+ ------------------ + ----------
| 8 |
+ ---------------------------- +

set global validate_password_length=1;

mysql> select @@ validate_password_length; # view the parameter values
+ ---------------------------- +
| @@ validate_password_length |
+ --- + -------------------------
| 4 |
+ -------------------- + --------
as long as less than 4 are set to 4.
So that you can simply modify the password
update user set authentication_string = password ( 'password: root') the WHERE the User = 'root';
flush privileges;
quit: quit
to restart the service: service mysqld restart
into the MySQL
MySQL -u root -proot
success!
3 windows:

Enter the mysql installation directory and copy my-default.ini, named my.ini


Editing my.ini
add [mysqld] under skip-grant-tables
to save.

Restart mysql: 1, net stop mysql 2 , net start mysql
enter MySQL
MySQL -u root -p
no password, enter directly
input use mysql
modified root password
update user set authentication_string = password ( 'new password') where user = 'root';
flush privileges;
quit: quit
restart mysql again: 1, net stop mysql 2, net start mysql
test for success is whether the successful landing slightly.
mysql -u root -p <new password>
to complete!

Guess you like

Origin www.cnblogs.com/forforever/p/12650282.html