Connect to MySQL with unix sockets
On Unix, you can connect to the mysqld server by using two different ways: a Unix socket file (for example, /var/run/mysqld/mysqld.sock), or by using TCP/IP (for example, 127.0.0.1:3306
). A connection that is created with a Unix socket file is faster than TCP/IP but can only be used when connecting to a server on the same computer. When you use a Unix socket file, you can skip a hostname and port in the connection string.
Prerequisites
Linux only
Junixsocket JAR files: the junixsocket repository at github.com
JetBrains Rider must be on the host where the server is running (MySQL 8.0 Reference Manual at dev.mysql.com)
Step 1. Locate a Unix socket file
On the server host in the command line, run the following command:
mysql -u root -p -h 127.0.0.1 -e "select @@socket"Type a password for your
root
user and press Enter.
Step 2. Check the Unix socket connection from the command line
In the command line, run the following command:
mysql -u root -p -S /var/run/mysqld/mysql.sock
.Type a password for your
root
user and press Enter.
Step 3. Download third-party libraries
The Connector/J driver does not natively support connections to MySQL Servers with Unix domain sockets. To enable socket connection, you need to download third-party libraries. For more information about this limitation, see Connecting Using Unix Domain Sockets at dev.mysql.com.
Download the latest release from the junixsocket repository at github.com (for example, junixsocket-dist-2.3.2-bin.tar.gz).
Extract the downloaded archive. You need to add the following files from the lib directory to the MySQL driver in JetBrains Rider:
junixsocket-mysql-2.3.2.jar
junixsocket-native-common-2.3.2.jar, if you have a custom architecture try junixsocket-native-custom-2.3.2.jar
junixsocket-core-2.3.2.jar
junixsocket-common-2.3.2.jar
Step 4. Configure the MySQL driver in JetBrains Rider
In the Database tool window ( ), click the Data Source Properties icon .
In the Drivers section, click the MySQL driver and click the Duplicate button . Alternatively, press Ctrl+D.
Change the name of the duplicated driver (for example, MySQL socket).
On the General tab, click the Add button () and select Custom JARs.
In the file browser, navigate to a folder with third-party libraries (see Step 3). While pressing Ctrl, select the following files:
junixsocket-mysql-2.3.2.jar
junixsocket-native-common-2.3.2.jar, if you have a custom architecture try junixsocket-native-custom-2.3.2.jar
junixsocket-core-2.3.2.jar
junixsocket-common-2.3.2.jar
Click OK.
On the Advanced tab, find the socketFactory property, double-click the Value cell, and change the value to
org.newsclub.net.mysql.AFUNIXDatabaseSocketFactory
.Scroll down to the end of the property list, double-click the <user defined> cell and type
junixsocket.file
. Double-click the Value cell and type the path to your socket file (see Step 1).Click Apply.
Step 5. Create a connection to the MySQL server
In the Database tool window ( ), click the Data Source Properties icon .
In the Data Sources and Drivers dialog, click the Add icon () and select MySQL.
Check if there is a Download missing driver files link at the bottom of the data source settings area. As you click this link, JetBrains Rider downloads drivers that are required to interact with a database. The IDE does not include bundled drivers in order to have a smaller size of the installation package and to keep driver versions up-to-date for each IDE version.
You can specify your drivers for the data source if you do not want to download the provided drivers. For more information about creating a database connection with your driver, see Add a user driver to an existing connection.
On the Advanced tab, find the
serverTimezone
parameter in the list of options. Double-click the Value cell and type your server timezone (for example,UTC
).Click the General tab.
From the Driver list, select the driver that you created earlier (see Step 4).
In User and Password fields, specify your user credentials.
To ensure that the connection to the data source is successful, click the Test Connection link.