使用Unix Socket的JDBC MySQL连接 [英] JDBC MySQL connection using Unix Socket

查看:762
本文介绍了使用Unix Socket的JDBC MySQL连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux上使用 - skip-networking 选项使用MySQL。

I am using MySQL using the --skip-networking option on Linux.

我正在尝试连接基于J2EE的应用程序(使用JDBC来使用servlet)到MySQL数据库。

I am trying to connect my J2EE based application (using servlets) to the MySQL database using JDBC.

早些时候,当我使用MySQL并禁用 - skip-networking 选项时,我是连接到数据库:

Earlier when I was using MySQL with the --skip-networking option disabled, I was connecting to the database as:

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase","myuser","mypassword");

启用 - skip-networking 选项后,我试过了将其连接为:

After having enabled the --skip-networking option, I was trying to connect it as:

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mydatabase","myuser","mypassword");

但这似乎不起作用,我得到 java.lang.NullPointerException 当我尝试连接到我的应用程序中的数据库时。

But this does not seem to work, and I get java.lang.NullPointerException when I try to connect to the database in my application.

在评论出 - skip-networking 选项并使用旧版本之后JDBC语句,我可以连接到数据库。

After commenting out the --skip-networking option and using the old JDBC statement, I can connect to the database.

我能够通过命令行mysql客户端连接到数据库 - skip-networking 选项已启用。

I am able to connect to the database via the command line mysql client with the --skip-networking option enabled.

有人能告诉我如何从JDBC连接到数据库吗?我试着寻找它,但没有任何令人满意的答案有效。在此先感谢。

Can anyone tell me how to connect to the database from JDBC? I tried searching for it but could not any satisfactory answer that worked. Thanks in advance.

推荐答案

您根本无法做到这一点:MySQL JDBC驱动程序仅支持TCP / IP,并且 - 在Windows上 - 命名管道连接到数据库。因此,指定 - skip-networking 将不允许您使用JDBC MySQL Connector / J.

You simply cannot do this: the MySQL JDBC driver only supports TCP/IP and - on Windows - named pipes to connect to the database. Therefor specifying --skip-networking will not allow you to use JDBC MySQL Connector/J at all.

参见还 http://lists.mysql.com/java/8749


Java本身不支持unix域套接字,但由于你在windows上,你可以使用命名管道,[..]

Java itself doesn't support unix domain sockets, but since you're on windows, you can use named pipes, [..]

上面帖子中的死链接现在是 http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html

The dead-link in the above post is now http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html

这篇关于使用Unix Socket的JDBC MySQL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆