mysql80 遇到 1130 Host ‘localhost‘ is not allowed to connect to this MySQL server

mysql80 遇到 1130 Host ‘localhost’ is not allowed to connect to this MySQL server

參考:Mysql 8.0.13忘記密碼 重置密碼

問題產生的原因:期望局域網同事能訪問自己本地的mysql庫表

做了如下操作:

  1. select host, user, pligin from user; 查看了系統mysql庫-user表的加密規則,默認爲:在這裏插入圖片描述
  2. update user set plugin='mysql_native_password'; FLUSH PRIVILEGES; 修改了所有的規則爲mysql_native_password,並刷新MySQL的系統權限相關表,
  3. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; 開放權限
  4. 同事仍連不上我的庫,顯示我這邊不允許連接,懷疑是我本地沒開遠程權限,重啓了mysql。
  5. 出現問題:Host 'localhost' is not allowed to connect to this MySQL server ,我自己都連不上本地的mysql。

問題解決步驟:

  1. 停止mysql服務 or net stop mysql
  2. 繞過密碼自己訪問數據庫,cmd 在安裝路徑中運行 mysqld --console --skip-grant-tables --shared-memory,此時會停在這裏
  3. 新開cmd 輸入登錄命令:mysql -u root -p,輸入密碼處直接回車
  4. 還原mysql-user表中的加密規則
use mysql
update user set authentication_string=''where user='root';
  1. 清除登錄密碼,quit-mysql,關閉momom
use mysql
update user set plugin='caching_sha2_password'
quit
  1. 關閉以-console --skip-grant-tables --shared-memory啓動的MySQL服務
  2. 密碼已經置空,所以無密碼狀態登錄MySQL,輸入登錄命令:mysql -u root -p,輸入密碼處直接回車
  3. 設置新密碼,quit-mysql
    ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '新密碼';
    說什麼0 row生效??what,查user發現對應的host是%,然後這樣
    ALTER USER 'root'@'%' IDENTIFIED WITH caching_sha2_password BY '新密碼';
  4. 使用新密碼登錄。mysql -uroot -p****
  5. bingo
    bingo。。。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章