1.安裝完成后,登陸出錯,這時候需要修改/etc/my.cnf中的配置文件,跳過密碼驗證,進入MySQL。在配置文件中任意行輸入skip-grant-tables;

2.然后重啟服務;

3.登陸mysql
~]# mysql
或者~]# mysql -uroot -p
4.登陸進去之后進去開始修改密碼:
mysql> use mysql
mysql> update user set password=password('Root@123456') where user='root'
-> ;
ERROR 1054 (42S22): Unknown column 'password' in 'field list' ==>出錯了,mysql5.7里面mysql數據庫下已經沒有password這個字段了,password字段改成了authentication_string
5.重新輸入語句修改密碼:
mysql> use mysql
mysql> update user set password=password('Root@123456') where user='root' ==>或者(ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@123456')
-> ;
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 1
6.退出MySQL,將配置文件里的skip-grant-tables刪除掉。
mysql> quit
Bye
刪除配置文件里的ship-grant-tables,再重新啟動服務:
[root@localhost etc]# vi /etc/my.cnf
[root@localhost etc]# systemctl restart mysqld
[root@localhost etc]# systemctl status mysqld
7.重新登陸MySQL,需要密碼登陸才能成功。
或者MySQL剛完成安裝時都有臨時密碼,我們可以先獲取臨時密碼,登陸進去之后,在進行之前上面的操作,完成密碼修改。
~]# grep 'temporary password' /var/log/mysqld.log
