天天看點

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

以前一直是用本地的 MySQL 進行學習、開發,後來買了伺服器,伺服器上也搭好了環境,就準備開始用伺服器上的 MySQL 進行學習和開發,也遇到了一些坑,在此記錄一下。

現在我本地是可以正常遠端連接配接伺服器 MySQL 的,下面兩個圖用紅色塗鴉的是我伺服器的公網IP。

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)
Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

如果你不是這樣子的,請繼續往下看。要想伺服器的 MySQL 可以被本地遠端連接配接,先要進入伺服器 MySQL 中執行下面幾條語句。

進入 MySQL 輸入 ​

​use mysql;​

​​ 、​

​update user set host='%' where user='username';​

​(% 也可以是固定的 IP,預設是 localhost,即隻允許本地連接配接)。

我的 ​

​username​

​​ 是 ​

​root2​

​​,大家填自己的 ​

​username​

​。

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

再對這個使用者進行授權(不知道是不是必須的,為了保險起見,​

​password​

​ 是使用者的密碼)

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;      

再看一下對使用者授權是否成功。

show grants for 'username'@'%'      
Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

如果還不能進行遠端連接配接,看伺服器防火牆的 3306 端口設定好了沒。

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

即使可以正常遠端連接配接伺服器 MySQL,運作程式還是會報錯。

報錯資訊如下圖:

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

解決方法是: 資料庫使用者密碼用​

​""​

​​括起來。如​

​"012345"​

​。

這個解決方法是在一個論壇中看到的(找了兩天的資料發現的神奇操作,估計是因為資料庫密碼有字首0的原因吧,我的資料庫密碼就有字首0)。

這樣後,我的項目就可以正常運作了,如下圖。

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)