最近買了阿里云的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 -ADatabase changedmysql> 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:1mysql> flush privileges;
Query OK,0 rows affected (0.00 sec)mysql> quit
Bye