Your MySQL hostname defines the location where your MySQL database is hosted. If you want to connect to your database, you need to specify the MySQL hostname so that your application knows where to connect.
In most situations, including hosting a WordPress site at Kinsta, your MySQL hostname will be localhost.
Essentially, this means that your MySQL database is running on the same server as the application that you’re working with (like your WordPress site). We have a detailed article that explains the concept of localhost and how it applies to WordPress.
If you host your WordPress site at Kinsta, all you normally need to know is that your database hostname is localhost. But if you’d like to learn more about the topic, or need to connect remotely to a database, continue reading for a deeper explanation.
What Is MySQL Hostname?
The MySQL hostname defines the location of your MySQL server and database. If you want to connect to the information in a MySQL database, you’ll need to know the hostname. Again, the hostname is usually localhost, which indicates that the database is running on the same server as your application (e.g. WordPress).
On a WordPress site, your MySQL hostname is defined in your site’s wp-config.php file.
If you were to connect to your WordPress site’s server via FTP and open your wp-config.php file, you will see your MySQL hostname defined on the following line:
/** MySQL hostname */ define( 'DB_HOST', 'localhost' );
On most WordPress installs, the value will be defined as localhost.
How Do I Find the MySQL Hostname?
Let’s go through how to find your database’s hostname in common situations.
How Do I Find MySQL Hostname in Kinsta?
At Kinsta, your database’s hostname is localhost for all of your WordPress sites.
If you need to connect remotely to your WordPress site’s database at Kinsta, you can follow our tutorial on remote database access.
How Do I Find MySQL Hostname in cPanel?
By default, cPanel also uses localhost for its MySQL hostname.
However, it is possible for hosting providers to specify a remote database server instead. Unfortunately, there’s no default way to learn this from inside cPanel (unless your host has added their own tool).
If localhost isn’t working for you, your best bet is to reach out to your host’s support.
Or, you can use phpMyAdmin, which is the next option.
How Do I Find phpMyAdmin Hostname?
phpMyAdmin lets you view and edit your database. It also provides you with information on your MySQL hostname.
When you open phpMyAdmin, look for the Server information from the Database server box. You can see how, at Kinsta, phpMyAdmin indicates that the MySQL server is localhost:
If you need to connect remotely using the IP address/domain of your MySQL database, you can open the Variables menu from your phpMyAdmin homepage and search for “hostname” to find the actual domain or IP address of the database server:
You can access the phpMyAdmin homepage by clicking on the logo in the top-left corner.
Again, if you’re specifically looking to connect to your database remotely at Kinsta, we have a dedicated article showing you how to set that up.
In case you need to find MySQL port number follow this guide.
How to Find MySQL Hostname When It’s Not Localhost
In almost all situations, your MySQL will be localhost, especially with WordPress. However, if you’re trying to connect remotely to a MySQL database, the hostname will not be localhost.
If your hostname isn’t localhost, here are some tactics to discover it.
1. Ask Support
It might seem obvious, but often the simplest tactic is to just reach out to the support team behind the database that you’re trying to connect to. They should be able to provide you with the MySQL hostname.
2. Use phpMyAdmin
If you have access to phpMyAdmin, you can follow the method from the previous section to use phpMyAdmin to find your MySQL hostname by looking up the hostname variable.
3. Use the Domain Associated With the Database Server
If you know the domain name associated with your database server (e.g. the domain name associated with cPanel), you can look up the domain name’s A record using intoDNS to find the IP address for your MySQL server.
Your hostname defines the location of your MySQL database server. In most cases, especially when working with WordPress sites, you can use localhost as your hostname.
However, if you need to connect remotely to a database, you will need to find the IP address of your MySQL host to connect remotely.
If you enjoyed this tutorial, then you’ll love our support. All Kinsta’s hosting plans include 24/7 support from our veteran WordPress developers and engineers. Chat with the same team that backs our Fortune 500 clients. Check out our plans