Mac上mysql默认端口那件事

如果可以通过终端访问数据库,并且可以完成所有的操作,但是ecplise中无法和数据库建立连接,解决了常见的错误后还是报错,那很有可能是端口不匹配。小编就是把所有常见的错误解决后,还存在错误,比如

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.ConnectException
MESSAGE: Connection refused: connect

STACKTRACE:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.(Unknown Source)
at java.net.Socket.(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
at com.mysql.jdbc.Connection.(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Test.selectdb(Test.java:151)
at Test.main(Test.java:22)


** END NESTED EXCEPTION **



Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
at com.mysql.jdbc.Connection.(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Test.selectdb(Test.java:151)
at Test.main(Test.java:22)


折磨了几十个小时,最后发现Mac 本mysql的默认端口时3307,不是3306.废话不多说了,说说如何查看端口。

终端输入:    ps -ef | grep mysql   查看mysql的端口

查看安装文件中的端口:/Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

Mac上mysql默认端口那件事_第1张图片

修改和自己的一样就可以了。


几十个小时血的教训。

你可能感兴趣的:(Mac开发使用手册)