Connecting WordPress to Database using Unix Domain Socket.
According to a recent study by the Percona team, a significant performance improvement can be achieved when a “Unix Domain Socket” is used instead of a TCP/IP loopback for communication between database and application.
Although in most WordPress tutorials the database connection is made via a TCP/IP loopback, it is also perfectly possible for WordPress to communicate via a Unix Domain Socket, and thus take advantage of the speed gains. Of course, this is provided that the MySQL/MariaDB server is running on the same system and is also available on a Unix Domain Socket.
Use the following command to find the location of the MySQL/MariaDB Unix domain socket:
mysql -e "select @@socket"
This should give you an output similar to this.
+-------------------------+ | @@socket | +-------------------------+ | /run/mysqld/mysqld.sock | +-------------------------+
Now open wp-config.php of your site.
vi /var/www/virtual/example.com/htdocs/wp-config.php
And look for the “DB_HOST” directive which is ether:
define( 'DB_HOST', 'localhost' );
or
define( 'DB_HOST', '127.0.0.1' );
And change it to:
define( 'DB_HOST', 'localhost:/run/mysqld/mysqld.sock' );