Mysql

如何使用 MySQL v5.7 更改 MySQL ‘root’ 密碼?

  • October 19, 2019

目前環境:

mysql> show variables like "%version%";
+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| innodb_version          | 5.7.13                       |
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| tls_version             | TLSv1,TLSv1.1                |
| version                 | 5.7.13                       |
| version_comment         | MySQL Community Server (GPL) |
| version_compile_machine | x86_64                       |
| version_compile_os      | Linux                        |
+-------------------------+------------------------------+
8 rows in set (0.01 sec)

密碼更改命令使用者:

mysql> update user set password=PASSWORD("XXXX") where user="root";
ERROR 1054 (42S22): Unknown column 'password' in 'field list'

我錯過了什麼嗎?

在 MySQL 5.7 中,表欄位password中的mysql.user欄位被刪除,現在欄位名稱為authentication_string.

首先選擇數據庫:

mysql> use mysql;

然後顯示表格:

mysql> show tables;

您將找到該user表,並查看其欄位:

mysql> describe user;

你會意識到沒有欄位named password,password欄位是named authentication_string。所以,只需這樣做:

update user set authentication_string=password('XXXX') where user='root';

正如@Rui F Ribeiro 所建議的那樣,您也可以執行:

mysql> SET PASSWORD FOR 'root' = PASSWORD('new_password');

引用自:https://unix.stackexchange.com/questions/291319