登錄資料庫時,發現資料庫連接不上,報錯如下:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor:yes)
為了以后方便排查,這里記錄一下,
首先,停止MySQL服務
service mysqld stop
既然是密碼錯誤,那么就先跳過密碼驗證的步驟
#vim /etc/my.cnf
然后,搜索mysqld,找到[mysqld](port=3306上面那個):
/mysqld(在vim編輯狀態下直接輸入該命令可搜索文本內容),
注:windows下修改的是my.ini,
在 [mysqld] 底下添加陳述句:
skip-grant-tables
(注:skip-grant-tables:不啟動grant-tables授權表,作為啟動引數的作用:MYSQL服務器不加載權限判斷,任何用戶都能訪問資料庫)
這是用來跳過密碼驗證的,添加之后保存退出,
重新啟動MySQL服務
進入MySQL
mysql -u root -p
出現密碼輸入時,不用輸入直接按回車,就可以不用密碼就能登錄
修改密碼
mysql> update user set password=password(“新密碼”) where user=”用戶名”;
如果報錯:
ERROR 1054(42S22) Unknown column 'password' in 'field list'
原因: 5.7版本下的mysql資料庫下已經沒有password這個欄位了,password欄位改成了authentication_string
mysql> update user set authentication_string=password(“新密碼”) where user=”用戶名”;
#重繪MySQL權限相關的表
mysql> flush privileges;
mysql> exit;
密碼修改完畢
編輯my.cnf(Windows下my.ini),將上面添加的內容去掉(skip-grant-tables),
重啟MySQL
使用新密碼登錄即可
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/86101.html
標籤:AI
下一篇:排障——資料庫主從復制ERROR 3021 (HY000): This operation cannot be performed with a running slave io thread
