Access denied for user ‘root‘@‘localhost‘問題的解決
問題場景
在阿里雲上部署了一臺伺服器,CentOS6.8系統環境,安裝了MySql+Nginx+Git+vsftpd等軟體,在本地Linux終端以非root賬戶SSH遠端登入伺服器,在將專案打包釋出時遇到如題所示問題。程式碼中配置檔案裡的使用者名稱不是“root”,密碼正確,且該使用者名稱和密碼是配置在服務端資料庫的使用者表中的。但是在用瀏覽器呼叫跟資料庫互動介面時出錯:
嘗試解決
網上搜了一堆文章,主要集中在
(1)對root授權:無效
grant all privileges on *.* to root@localhost identified by '你為root設定好的密碼';
flush privileges;
(2)修改root密碼:無效
(3)修改配置:失效
(4)新增host:失效
最終解決
搜了一圈,雖然問題沒解決,但是我也搞懂了就是對root的授權出了問題。
那問題到底出在哪裡?
為什麼別人的方法對我這個情況都不適用?
我跟別人在相同解決方案的情況下有什麼變數不同?
——想清楚了這點,我找到了不同點:我使用的是自己的賬戶SSH遠端登入並進行授權操作
(1)SSH登入root管理員賬戶
(2)登入MySql
# mysql -u root -p
Enter password:
(3)執行授權命令
mysql> grant all privileges on *.* to root@'localhost' identified by '密碼';
mysql> flush privileges;
或
mysql> grant all privileges on *.* to root@'%' identified by '密碼';
mysql> flush privileges;
(4)退出再試
mysql> quit
Bye
(5)再次登入
然後,問題就解決了~
相關文章
- ubuntu mysql Access denied for user root@localhostUbuntuMySqllocalhost
- mysql 1045, "Access denied for user 'root'@'localhost' (using password: NO)"MySqllocalhost
- 解決Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)的方法MySqlErrorlocalhost
- MySQL 8.0.13 密碼問題 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)MySql密碼Errorlocalhost
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:YES)Errorlocalhost
- 啟動報錯:Access denied for user 'root'@'localhost' (using password:YES)localhost
- Ubuntu18.04:mysql:ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘UbuntuMySqlErrorlocalhost
- 報錯”ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)”Errorlocalhost
- java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘ (using password: YES)JavaSQLExceptionlocalhost
- mac os x 安裝mysql遇到 Access denied for user ‘root‘@‘localhost‘ (using password: YES)的解決方法MacMySqllocalhost
- Linux錯誤 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)LinuxErrorlocalhost
- MySQL使用普通使用者訪問返回ERROR 1698 (28000): Access denied for user 'root'@'localhost'MySqlErrorlocalhost
- SpringBoot中yml配置java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘ (using password: NOSpring BootJavaSQLExceptionlocalhost
- SQLSTATE[HY000] [1045] Access denied for user ‘root‘@‘localhost‘ (using password: YES)”錯誤的隱藏解決辦法SQLlocalhost
- vue專案中連線MySQL時,報錯ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password:YES)VueMySqlErrorlocalhost
- MySQL系列:Docker安裝 MySQL提示錯誤:Access denied for user'root'@'localhost' (using password:yes)MySqlDockerlocalhost
- 【本人親測 已解決】044 - Access denied for user ‘root‘@‘%‘ to database ‘資料庫名稱‘Database資料庫
- Navicat遠端連線MySQL 提示1045 - Access denied for user 'root'@'223.74.158.192'(using password:YES)MySql
- Permission denied:user=xxx,access=WRITE,inode=xxx
- Access denied for user 'default'@'%' to database 'shop'報錯Database
- mybatis進行資料庫建表 CREATE command denied to user 'root'@'127.0.0.1' for table 問題MyBatis資料庫127.0.0.1
- 寶塔解決 mkdir() Permission Denied 的問題
- App\User 替換為 App\Models\User 的問題解決!APP
- 解決SpringBoot頁面localhost 404問題,即Whitelabel Error Page問題Spring BootlocalhostError
- Caused by: java.sql.SQLException: Access denied for user 'dell-pc'@'xxxxx' (using password: YES)JavaSQLException
- hive建立分割槽表報錯AccessControlException Permission denied: user=NONE, access=WRITE, inodeHiveExceptionNone
- Windows git remote: HTTP Basic: Access denied 錯誤解決辦法WindowsGitREMHTTP
- NFS掛載時出現”access denied by server while mounting”的解決方法NFSServerWhile
- localhost拒絕訪問的解決方法localhost
- Delta Magisk root後解決adb的報錯問題
- 關於解決Server Tomcat v9.0 Server at localhost failed to start的問題ServerTomcatlocalhostAI
- nginx中報Access denied.Nginx
- 如何解決 oppo 手機 root 的問題
- 關於IPC和PTH使用者許可權問題,psexec拒絕訪問(Access Denied)的原因
- NodeJS+Express解決跨域問題:Access-Control-Allow-OriginNodeJSExpress跨域
- Apache解決Access-Control-Allow-Origin多域名跨域問題Apache跨域
- 解決 IDEA 中 Wrong root element less..(Ctrl+F1)Inspection info: This inspection checks if root ta 的問題Idea
- Docker + maven build problem — unix://localhost:80: Permission deniedDockerMavenUIlocalhost