您好,登錄后才能下訂單哦!
這篇文章主要介紹“Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)如何解決”,在日常操作中,相信很多人在Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)如何解決問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)如何解決”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
很久沒用這臺電腦的mysql了,今天需要連接數(shù)據(jù)庫,啟動數(shù)據(jù)庫報錯:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
查閱資料后知道了,應(yīng)該使用已知的用戶名和密碼登陸
mysql -u root -p
然而密碼忘了,試了好幾遍終于試出來了:
然后修改成通用的密碼,不亂折騰了:
發(fā)現(xiàn)很多教程都過時了,我的版本是Server version: 8.0.19 MySQL ,最新的方法:
mysql> use mysql; mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123'; mysql> flush privileges;
退出驗證下看看有沒有成功:
可以看到修改密碼成功了。
然后呢,我又假裝密碼忘了,把忘記密碼的修改密碼方法演示一下:
首先先停止mysql服務(wù)。可通過net stop mysql
或者任務(wù)管理器中關(guān)閉。
以管理員權(quán)限操作:(這是第一個窗口)
進入命令提示符(管理員登陸)操作,進入mysql目錄中bin文件夾下,mysql8.0與其他版本不同的地方在于無法直接使用mysqld --skip-grant-tables來跳過密碼登錄。在這我們使用mysqld -console --skip-grant-tables --shared-memory
來跳過權(quán)限驗證。
輸入執(zhí)行后沒有反饋,新開一個管理員窗口重新執(zhí)行。(這是第二個窗口)
進入目錄后,確保自己已經(jīng)關(guān)閉了Mysql的服務(wù):net stop mysql
關(guān)閉Mysql服務(wù)之后,繼續(xù)在D:\mysql-8.0.19-winx64\bin目錄下進行操作:
輸入
mysqld --console --skip-grant-tables --shared-memory
在輸入這行代碼之后,如下顯示,我們就已經(jīng)成功跳過Mysql的密碼登錄了:
在上述步驟之后,再打開一個管理員模式運行的cmd.exe (這是第三個窗口)
進入mysql下的bin目錄后,直接登錄mysql
不需要通過net start mysql
打開mysql服務(wù)
在命令行中輸入以下代碼
d: cd D:\mysql-8.0.19-winx64\bin(此處輸入自己電腦上的安裝目錄) mysql -u root -p
如圖:
此時會顯示讓你輸入密碼,直接回車,就可以成功連接Mysql。
輸入代碼,將密碼設(shè)置為空(此時還不能直接修改密碼,必須先設(shè)置為空,否則會報錯)
輸入:
use mysql; (使用mysql數(shù)據(jù)表) update user set authentication_string='' where user='root';(將密碼置為空) quit; (然后退出Mysql)
操作如圖:
這里分為兩個部分
1.關(guān)閉前兩個cmd窗口(一定要關(guān)閉!); 2.在第三個窗口中輸入代碼;
net stop mysql(關(guān)閉mysql服務(wù),雖然會顯示沒有開啟服務(wù),但是以防萬一) net start mysql(再打開mysql服務(wù))
(這里不要嫌麻煩,如果上一個mysql服務(wù)沒關(guān)閉,我們依舊是無密碼登陸)
操作如圖:
接著輸入:
cd D:\mysql-8.0.19-winx64\bin (此處輸入自己電腦上的安裝目錄) mysql -u root -p (此處會顯示輸入密碼,直接回車就好了,第四步我們已經(jīng)將他置為空了) ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';(更改密碼)
如圖:
輸入:
quit(退出mysql) mysql -u root -p (輸入新密碼,再次登錄)
圖示:
成功!
到此,關(guān)于“Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)如何解決”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。