我在這里用到的MySQL可視化工具為Navicat,這個錯誤是這樣說的:1045 Access denied for user 'root'@'localhost' (using password:YES)
這個意思是說:用戶“root”@本地主機的訪問被拒絕
查了很久,發現新的mysql8.0以上在my.ini下的[mysqlld]添加skip-grant-tables不能讓任何用戶都能訪問數據庫。
那么新的數據庫怎么辦呢?
1、管理員權限下運行cmd,關閉服務 net stop mysql
2、進入到MySQL安裝下bin目錄 執行 :mysqld --console --skip-grant-tables --shared-memory能讓任何用戶都能訪問數據庫
執行完后無法輸入,不要關閉,另外打開一個cmd
3、在新的cmd下運行mysql -u root -p就能免密進入(我這里是自己輸入的密碼。。。)
4、運行sql語句
- use mysql; 使用MySQL數據庫
- update user set authentication_string='' where user='root'; 將密碼改為空
- flush privileges; 刷新
- ALTER user 'root'@'localhost' IDENTIFIED BY '1234'; 修改密碼1234
參考博客https://blog.csdn.net/qq_27820551/article/details/101488430