1. 程式人生 > >Caused by: java.sql.SQLException: Access denied for user 'root'@'host' (using password: YES)

Caused by: java.sql.SQLException: Access denied for user 'root'@'host' (using password: YES)

解決辦法:

1. SELECT * FROM mysql.user WHERE USER='root';

2. GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.107.61' IDENTIFIED BY 'root';

3. FLUSH PRIVILEGES;

解決後的截圖: 


錯誤的具體現象: 
1,開發同學都可以在自己電腦上連線測試伺服器上的資料庫 
2,在伺服器上通過命令mysql -uroot -proot可以連上資料庫,但是通過mysql -uroot -proot -h192.168.107.61(伺服器ip)連不上 
3,程式sql日誌,查詢可以正常輸出,更新就會報超時,然後報這個錯誤。

執行完解決辦法的sql後,問題解決。不需要重新mysql和tomcat服務。 

實在沒理解為什麼查詢可以列印查詢結果,更新報錯。重新授權後,更新就可以了。同樣的資料,同樣的程式碼。


轉載自>https://blog.csdn.net/zl544434558/article/details/54317696