Yogesh Chauhan's Blog

How to add MySQL alternate port and sockets/pipes in WordPress?

in WordPress on December 27, 2021

Read more about database configurations in this post:

How to update database configurations in WordPress?

We learned about setting up a database host in that post.

Let’s explore more setting in case you need to do that.

How to set MySQL alternate port?

You need change the value of the DB_HOST in wp-config for setting up a host. With the same line of code, you can also set an alternate port. Of course, all changed are need to be made in wp-config.php file.

This is how you can set MySQL alternate port for localhost:


define( 'DB_HOST', '127.0.0.1:1111' );

or you can literally use the word localhost instead of an ip address. It works many times depending on your machine configurations.


define( 'DB_HOST', 'localhost:1111' );

Hosts such as Dreamhost has a specified MySQL servers. In that case, you can set the port like this:


define( 'DB_HOST', 'mysql.example.com:1111' );

Replace 1111 with the port number provided by your server host in all the cases above.

MySQL sockets or pipes

For the hosts that uses Unix sockets or pipes, set DB_HOST value like this:


define( 'DB_HOST', '127.0.0.1:/var/run/mysqld/mysqld.sock' );
// or define( 'DB_HOST', 'localhost:/var/run/mysqld/mysqld.sock' );
// or define( 'DB_HOST', 'example.tld:/var/run/mysqld/mysqld.sock' );

You need to replace /var/run/mysqld/mysqld.sock with the socket or pipe information provided by your host.

Read more about it on WordPress documentation.


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Is monitoring an employee’s work on a computer a desirable or undesirable activity?MiscellaneousAdvanced Array Methods in JavaScript (with examples)JavaScriptHow to float an image around texts?CSSSolution for “Yarn build: Failed because of a stylelint error”WordPressIntroduction to components and templates Part 3: Data bindingAngularSorting Object Arrays in JavaScriptJavaScript