MySQL8.0修改密碼的正確姿勢(shì)分享
前言
mysql 更新完密碼,總是拒絕連接、登錄失敗?MySQL8.0 不能通過(guò)直接修改 mysql.user 表來(lái)更改密碼。正確更改密碼的方式備注: 清空root密碼
MySQL8.0 不能通過(guò)直接修改 mysql.user 表來(lái)更改密碼。
因?yàn)閍uthentication_string字段下只能是MySQL加密后的43位字符串密碼,其他的導(dǎo)致錯(cuò)誤。錯(cuò)誤不報(bào)出,但是無(wú)法再登錄mysql,總是會(huì)提示 無(wú)法認(rèn)證。
參考:MySQL8.0
mysql> USE mysql; Database changed mysql> UPDATE user SET authentication_string="123456" WHERE user="root"; Query OK, 1 row affected (0.39 sec) Rows matched: 1 ?Changed: 1 ?Warnings: 0 mysql> FLUSH privileges; ?# 刷新保存 Query OK, 0 rows affected (0.13 sec)
mysql 5.7.9 之后取消了password 函數(shù),authentication_string=password("123456") 會(huì)報(bào)錯(cuò)
C:\WINDOWS\system32>mysql -u root -p
Enter password: ******
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
1234567891011121314
如果 你已經(jīng)這樣更改密碼,并且導(dǎo)致了無(wú)法進(jìn)入mysql。本人表示同情之時(shí),還為了你提供了詳細(xì)的解決方案。請(qǐng)查看本文備注:清空root 密碼
正確更改密碼的方式
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "your_password"; mysql> USE mysql; Database changed mysql> ALTER USER 'root'@'localhost' IDENTIFIEED WITH mysql_native_password BY "markjun"; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIEED WITH mysql_native_password BY "markjun"' at line 1 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "markjun"; Query OK, 0 rows affected (0.18 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "123456"; Query OK, 0 rows affected (0.08 sec) mysql> SELECT user, authentication_string FROM user; +------------------+------------------------------------------------------------------------+ | user | authentication_string | +------------------+------------------------------------------------------------------------+ | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +------------------+------------------------------------------------------------------------+ 4 rows in set (0.00 sec) mysql> FLUSH privileges; Query OK, 0 rows affected (0.38 sec) mysql> quit; Bye F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root -p Enter password: ******* ... mysql>
- 備注: 清空root密碼
停止 MySQL 任務(wù) net stop MySQL
mysqld 命令 mysqld --console --skip-grant-tables --shared-memory
無(wú)密碼進(jìn)入mysql mysql -u root
清空root 密碼 UPDATE user SET authentication_string="" WHERE user=“root”;
另一個(gè)終端無(wú)密碼進(jìn)入
F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root -p Enter password: ******* ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 ... Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> USE mysql; Database changed mysql> SELECT user, authentication_string FROM user; +------------------+------------------------------------------------------------------------+ | user | authentication_string | +------------------+------------------------------------------------------------------------+ | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | root | 123456 | +------------------+------------------------------------------------------------------------+ 4 rows in set (0.34 sec) mysql> UPDATE user SET authentication_string="" WHERE user="root"; Query OK, 1 row affected (0.20 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT user, authentication_string FROM user; +------------------+------------------------------------------------------------------------+ | user | authentication_string | +------------------+------------------------------------------------------------------------+ | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | root | | +------------------+------------------------------------------------------------------------+ 4 rows in set (0.00 sec) mysql> FLUSH privileges; Query OK, 0 rows affected (0.10 sec) mysql> quit; Bye
停止 mysqld 任務(wù),Ctrl+C 結(jié)束任務(wù),或者直接關(guān)閉 運(yùn)行 mysqld 的 cmd 終端。
需要先停止運(yùn)行上述 mysqld 任務(wù),否則報(bào)錯(cuò)
F:\MySQL\mysql-8.0.13-winx64\bin>net start mysql
MySQL 服務(wù)正在啟動(dòng) .
MySQL 服務(wù)無(wú)法啟動(dòng)。服務(wù)沒(méi)有報(bào)告任何錯(cuò)誤。
請(qǐng)鍵入 NET HELPMSG 3534 以獲得更多的幫助。
先停止上述 mysqld 任務(wù)
F:\MySQL\mysql-8.0.13-winx64\bin>net start mysql
MySQL 服務(wù)正在啟動(dòng) ...
MySQL 服務(wù)已經(jīng)啟動(dòng)成功。
現(xiàn)在 mysql root 已經(jīng)沒(méi)有了密碼
F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g....
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
總結(jié)
到此這篇關(guān)于MySQL8.0修改密碼的正確姿勢(shì)的文章就介紹到這了,更多相關(guān)MySQL8.0修改密碼姿勢(shì)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章

Java將excel中的數(shù)據(jù)導(dǎo)入到mysql中

MySQL判斷查詢條件是否包含某字符串的7種方式總結(jié)

MySQL之權(quán)限以及設(shè)計(jì)數(shù)據(jù)庫(kù)案例講解

MySQL8.0.21.0社區(qū)版安裝教程(圖文詳解)

數(shù)據(jù)庫(kù)連接池以及sequelize實(shí)現(xiàn)增刪改查等操作指南

MYSQL ZIP免安裝版配置步驟及圖形化管理工具mysql-workbench