MySQL Connector/J 8.0 Developer Guide
Connector/J does not natively support connections to MySQL
Servers with Unix domain sockets. However, there is provision
for using 3rd-party libraries that supply the function via a
pluggable socket factory. Such a custom factory should implement
the com.mysql.cj.protocol.SocketFactory
interface or the legacy
com.mysql.jdbc.SocketFactory
interface of
Connector/J. Follow these requirements when you use such a
custom socket factory for Unix sockets :
The MySQL Server must be configured with the system variable
--socket
(for native
protocol connections using the JDBC API) or
--mysqlx-socket
(for
X Protocol connections using the X DevAPI), which must
contain the file path of the Unix socket file.
The fully-qualified class name of the custom factory should
be passed to Connector/J via the connection property
socketFactory
. For example, with the
junixsocket library, set:
socketFactory=org.newsclub.net.mysql.AFUNIXDatabaseSocketFactory
You might also need to pass other parameters to the custom
factory as connection properties. For example, for the
junixsocket library, provide the file path of the socket
file with the property junixsocket.file
:
junixsocket.file=path_to_socket_file
Fore release 8.0.21 and earlier: When
using the X Protocol, set the connection property
xdevapi.useAsyncProtocol=false
(that is
the default setting for Connector/J 8.0.12 and later). Unix
socket is not supported for asynchronous socket channels.
When xdevapi.useAsyncProtocol=true
, the
socketFactory
property is ignored (the
connection property
xdevapi.useAsyncProtocol
has been
deprecated since release 8.0.22).
For X Protocol connections, the provision to use custom socket factory for Unix socket connefctions is only available for Connector/J 8.0.12 and later.