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

$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost' 

解决方法一:

在文件/etc/mysql/my.cnf 中添加

[mysqld]
skip-grant-tables

重启mysql,搞定!

解决方法二:

使用sudo mysql进入到mysql

alter user 'root'@'localhost' identified with mysql_native_password by '密码';

假如你安装的是MariaDB,上面指令中的with可以用,也可以要改为 via

alter user 'root'@'localhost' identified via mysql_native_password by '密码';

  或者分解为

alter user 'root'@'localhost' identified via mysql_native_password;

alter user 'root'@'localhost' identified by '密码';

如果密码设置的过于简单,会出现以下错误

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

设定好密码后,再修改密码设定规则,改为简单的设置规则

mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.02 sec)
mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

就可以把密码设置成’1234'这一类比较简单的了

  

 

posted @ 2021-01-26 11:17  华小电  阅读(436)  评论(0编辑  收藏  举报