linux安裝了mysql之后初始化密碼獲取:出現了下面的內容,密碼很尷尬,無法用root登錄:
1 grep 'temporary password' /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: 4)ZqW0IooQ(a
出錯如下:
[root@iZuf655czz7lmtn8v15tsjZ mysql]# mysql -uroot -p 4)ZqW0IooQ(a -bash: syntax error near unexpected token `)'
百度一番找到直接修改登錄方式,無密碼登錄,修改密碼:
1、執行以下命令
vi /etc/my.cnf
2、找[mysqld],在下面添加如下內容:
[mysqld] skip-grant-tables
3、重啟mysql:
service mysqld restart
4、無密碼登錄mysql
[root@iZuf655czz7lmtn8v15tsjZ mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.28 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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>
5、執行以下命令,本以為順風順水,然鵝。。。
update mysql.user set Password=PASSWORD('123456') where USER='root';
。。。
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
6、看下這個 mysql.user 表里是些啥。。。
select * from mysql.user;
看來看去就這個列名順眼: 
於是我改了下語句:
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
。。。wtf(原來,mysql5.7更改密碼應該采用命令ALTER USER 'root'@'localhost'IDENTIFIED BY '********'其中密碼的命名規則有所改變:MySQL 設置的密碼中必須至少包含一個大寫字母、一個小寫字母、一個特殊符號、一個數字,密碼長度至少為8位)
7、好在改完了,接下來執行回退,回到/etc/my.cnf中刪除新增的skip-grant-tables重啟即可
