Can't connect to MySQL server on '127.0.0.1' (61) 或者M(jìn)ysql端口號(hào)不為3306問題

1.初學(xué)java鏈接數(shù)據(jù)庫,出現(xiàn)

com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@3f72acc1 --
Acquisition Attempt Failed!!! Clearing pending acquires.

While trying to acquire a needed new resource, we failed to succeed more than   
the maximum number of allowed acquisition attempts (30). Last acquisition 
attempt exception:   

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

懷疑是數(shù)據(jù)庫沒鏈接成功!
查看eclispe端口號(hào)為3306,于是查看mysql的端口號(hào),終端輸入:

show global variables like 'port';

后顯示:


image.png

果然不是3306 于是決定修改方法為

1.停止MySQL服務(wù)
2.在com.oracle.oss.mysql.mysqld.plist文件中的ProgramArguments下添加<string>--port=3306</string>保存退出
這里直接修改可能會(huì)提示沒有權(quán)限
3.打開終端輸入cd 到com.oracle.oss.mysql.mysqld.plist所在目錄
輸入

sudo vim  com.oracle.oss.mysql.mysqld.plist

編輯為如下圖


image.png

保存
重啟mysql

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容