How to Set a Custom Database Port in WordPress

WordPress relies on a MySQL database to store and manage your website’s data. By default, WordPress assumes that the MySQL database is running on the standard port 3306. However, there might be scenarios where your MySQL server is configured to use a different port, and you need to inform WordPress about it.

In this tutorial, we’ll guide you through the process of setting a custom database port in WordPress by editing the wp-config.php file.

Step 1: Locate the wp-config.php file

Access your WordPress installation directory, and find the wp-config.php file. You can use a text editor or an FTP client to edit the file.

Step 2: Open the wp-config.php file

Open the wp-config.php file in your preferred text editor.

Step 3: Locate the database connection settings

Look for the section in the file that contains the database connection settings. It should look similar to the following:

define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_user');
define('DB_PASSWORD', 'your_database_password');
define('DB_HOST', 'localhost');

Step 4: Add the custom port information

Modify the DB_HOST definition to include the custom port. For example, if your database is running on port 12345, update it like this:

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

If your database is on a different server, specify the IP address and port:

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

Replace ‘12345’ with your actual custom port number.

Step 5: Save the changes

Save the wp-config.php file.

Step 6: Test your site

Visit your WordPress site to ensure that it’s working correctly with the custom database port. If everything is set up correctly, your WordPress site should now be able to connect to the MySQL database using the specified port.

Conclusion

Setting up a custom database port in WordPress is a straightforward process. By making this adjustment in the wp-config.php file, you can ensure that your WordPress site communicates with the MySQL database on the correct port.

Remember to always make a backup of your wp-config.php file before making changes, and double-check the database configuration to ensure accuracy.

Feel free to share this tutorial with others who might find it helpful!