使用Java与Unix套接字连接到MySql以避免JDBC的TCP/IP开销?

问题描述:

是否可以使用Java与MySql建立Unix套接字连接以避免JDBC的TCP/IP开销?

Is it possible to make a Unix socket connection to MySql with Java to avoid JDBC's TCP/IP overhead?

有没有人知道一个图书馆(或者几个图书馆)来实现这一目标?

Does anyone know a library (or a few libraries, perhaps) that makes this possible?

JDBC只是一个接口规范.它不会增加任何TCP/IP开销.如果开销很大,那是由JDBC驱动程序引起的.还有用于内存或文件数据库的JDBC驱动程序,根本不使用TCP/IP.

JDBC is only an interface specification. It does not add any TCP/IP overhead. If there is overhead it is caused by the JDBC driver. There are also JDBC drivers for in memory or file databases and don't use TCP/IP at all.

MYSQL JDBC驱动程序是JDBC Type 4驱动程序.这意味着它不使用任何本机代码来访问数据库.如果Java没有方法来访问unix套接字,则驱动程序也不能使用它们.

The MYSQL JDBC driver is a JDBC Type 4 driver. That means it does not use any native code to access the database. If Java has no method to access unix sockets, the driver can not use them either.[1]

如果您真的想使用unix套接字,则可以使用似乎支持unix套接字的MySQL ODBC驱动程序,然后使用JDBC-ODBC桥从Java访问它.

If you really want to use a unix socket maybe it is possible to use MySQL's ODBC driver which seems to supports unix sockets and then use a JDBC-ODBC bridge to access it from Java.