MySQL JDBC Connection Using Unix Socket

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

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

Previously, when I used MySQL with the -skip-networking option disabled, I connected to the database as follows:

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

After enabling the -skip-networking option, I tried to connect it as:

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

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

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

I can connect to the database through the mysql command line client with the -skip-networking option enabled.

- , JDBC? , . .

+4
4

: JDBC MySQL TCP/IP - Windows - . --skip-networking JDBC MySQL Connector/J .

. http://lists.mysql.com/java/8749:

Java unix, , , [..]

http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html

+5

UNIX- Mysql JDBC Connector/J, socketFactory.

jdbc:mysql:///?user=test&password=test&socketFactory=<classname>&<socket>=/tmp/mysql.sock

, . Mysql - , factory .

Java UNIX junixsocket, ​​ socketFactory. MySQL Unix Domain Sockets, .


Java UNIX Q & A:

+6

, ( , Intellij IDE) Mysql JDBC Connector/J ( 5.1) , socketFactory,

JDBC: MySQL://: 3306/database_name = ​​/TMP/mysql.sock

+2

JDBC MariaDB Unix, MySQL Connector/J JDBC. jdbc url MariaDB: jdbc:mariadb://localhost:3306/revmgt?localSocket=/var/run/mysqld/mysqld.sock

It is worth noting that this requires the inclusion of the JNA library, since the MariaDB driver uses internal sockets through JNA from the inside. I have seen speed improvements for processor-related java processes when using unix domain sockets. I believe this was largely due to work offloading from the java process to native code, freeing processor cycles for already processed Java processes with the processor.

+2
source

All Articles