在linux下,无法通过jdbc连接到mysql的问题

王朝java/jsp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

今天在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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有