今天在debian中用jdbc连mysql,连接不上
报错:
Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.ConnectException)
以为是mysql没有启动,但是用命令行可以连接到数据库。
然后在网上找到一个回答说是驱动程序有问题,于是就下了一个最新版的,可是同样报错,不过错误信息有些不同而已:
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused
最后发现其实就是安装的数据库没有开发socket连接。
由于我的mysql是用deb包安装的,默认没有打开socket连接方式。
解决办法:
将/etc/mysql/my.cnf 中的
skip-networking注释掉就好了.
是在这里找到的解决办法:
http://forums.liferay.com/index.php?showtopic=386
原文:
installed mysql as .deb package and by default it has disabled networking. Eventhough the server daemon was listening on 3306, mysql was not accepting connections through tcp.
That is why mysql command line worked and a connection through the web app didn't work. Now I enabled mysql networking and it works.
If any of you are facing the same problem (debian/mysql/datasource error), you have to enable networking for mysql. You do that my commenting out skip-netowrking lline in /etc/mysql/my.cnf and you have to restart the database.