操蛋的linux改mysql密码(1054和1819错误)

最近买了阿里云的linux服务器,帮我装好tomcat,jdk,mysql镜像,不怎么会用,在朋友帮助下勉强启动,但是初始的mysql密码太过复杂。看了网上linux修改mysql密码的教程鱼龙混杂,跟着试着走却发现很多bug(1045,和1819错误),就想着把步骤总结一下。
linux mysql密码以及错误的解决
输入:mysql -uroot -p
输入:(密码 )//ps:输入密码登陆成功
mysql>use mysql; //指明要操作数据库
mysql> update user set password=passworD(“test”) where user=’root’;更改密码
mysql> flush privileges;
mysql> exit;
可能会报错,未识别password;
就把mysql> update user set password=passworD(“test”) where user=’root’;更改密码
换成mysql> update mysql.user set authentication_string=password(‘123456’) where user=’root’;
可能还会报错说密码不符合规范,
那么就修改 validate_password_policy;这个和validate_password_policy有关,具体步骤
mysql> set global validate_password_policy=0;
mysql> select @@validate_password_length;
mysql> select @@validate_password_length;
mysql> set global validate_password_length=1;
mysql> select @@validate_password_length;//再次查看会发现数值变成四,这样再设置密码
mysql> update mysql.user set authentication_string=password(‘123456’) where user=’root’;
mysql> flush privileges;//刷新
mysql> quit//离开

就成功了
运行图:

[root@iZkt0hekctiwafZ ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set password=password('123456') where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'//意思是识别不出password 要把passoword改成authentication_string
mysql> update mysql.user set authentication_string=password('123456') where user='root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements//意思是规则不满足

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

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          8 |
+----------------------------+
1 row in set (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          8 |
+----------------------------+
1 row in set (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          4 |
+----------------------------+
1 row in set (0.00 sec)

mysql> update mysql.user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

在通过本机的nivicat formysql或者其他工具就可以用新密码登陆服务器的数据库了。

猜你喜欢

转载自blog.csdn.net/qq_40693171/article/details/80246714