JDBC MySQL connection using Unix Socket

后端 未结 4 1544
有刺的猬
有刺的猬 2020-12-06 11:57

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

Trying to connect my J2EE based application (using servlets) to the MySQL database using JDBC.

4条回答
  •  醉酒成梦
    2020-12-06 12:32

    If you want to use UNIX sockets with the Mysql JDBC Connector/J you need to provide a socketFactory.

    jdbc:mysql:///?user=test&password=test&socketFactory=&=/tmp/mysql.sock

    So this will vary with the implementation you use. By default, Mysql does not ship with any implementation for that, just provides an example for such a factory in it's source-code.

    There is an existing UNIX socket Java library named junixsocket which also has such a socketFactory class implementation. An example is outlined in Connecting to a MySQL database via Unix Domain Sockets which is part of their documentation.


    You can find more Java UNIX socket library alternatives in related Q&A material:

    • UNIX socket implementation for Java?

提交回复
热议问题