Updated: 30 November 2026 · Applies to: cPanel shared and reseller hosting, cPanel VPS and dedicated servers; connection tests with MariaDB 11.4
Use localhost as the database host for a website that runs on the same hosting account as its database, which is the normal setup on cPanel hosting. Use a remote host name or IP address only when the application runs on a different machine than the database, for example a desktop tool on your computer or an app on another server. In that case you must also allow that machine in cPanel's Remote Database Access first.
Which host to enter
- Website on the same cPanel account (WordPress, Joomla, a PHP script): host
localhost. - Your computer (MySQL Workbench, HeidiSQL, DBeaver) or another server: host is your domain name or the server's IP address, port
3306, and that computer's IP must be allowed in Remote Database Access. - A host name shown under Remote Database Host in cPanel's Manage My Databases: according to cPanel, this section only appears when the server keeps its databases on a separate database server, and it shows the address your hosting provider set up. If you see it, use that address instead of
localhost.
Whichever host you use, the database name and the database user are the full names shown in Databases > Manage My Databases, including your cPanel username prefix, for example alice_shop and alice_shopuser.
Example: WordPress wp-config.php
define( 'DB_NAME', 'alice_shop' ); define( 'DB_USER', 'alice_shopuser' ); define( 'DB_PASSWORD', 'your-database-password' ); define( 'DB_HOST', 'localhost' );
Other applications have the same four settings under similar names, such as host, hostname or server.
localhost and 127.0.0.1 are not the same
Both point at the same server, but MySQL and MariaDB clients treat them differently:
localhostconnects through a local socket file, not the network.127.0.0.1connects over TCP/IP on port 3306.
We checked this with the MariaDB 11.4 client. Connecting with -h localhost:
mariadb -h localhost -u alice_shopuser -p -e "status" alice_shop
Output (shortened):
Connection: Localhost via UNIX socket UNIX socket: /run/mysqld/mysqld.sock
The same command with -h 127.0.0.1 showed Connection: 127.0.0.1 via TCP/IP and TCP port: 3306.
This matters because a database user is allowed per host. In our lab, a user created only for localhost logged in fine with -h localhost, but was refused with -h 127.0.0.1:
ERROR 1045 (28000): Access denied for user 'bob'@'127.0.0.1' (using password: YES)
So if you see Access denied with 127.0.0.1 and the password is correct, try localhost. If your application really needs a TCP connection (for example through an SSH tunnel on another port), use 127.0.0.1 together with that port.
Connecting from another computer or server
cPanel databases accept local connections only until you allow a remote address. To allow one:
- Log in to cPanel and open Databases > Remote Database Access (called Remote MySQL in older versions).
- In Host, enter the public IP address of the computer or server that will connect. According to cPanel, you can also enter a host name, an IPv6 address, or a range with the
%wildcard, such as203.0.113.%. - Add a note in Comment if you like, then click Add Host.
- In your application, set the host to your domain name or the server's IP address, port
3306, with the full database name and user.
Only add fixed IP addresses you trust, and remove them when you no longer need them. Never add % on its own: that allows the whole internet to try your database passwords. Remote connections are also slower than localhost, so keep a website and its database on the same server when you can.
If the connection still times out after you added your IP, a firewall may be blocking port 3306. Whether remote connections are open on your plan can differ per server, so open a ticket with your IP address and we check it. More detail: How can I access MySQL database remotely? and Remote MYSQL connection not working in cPanel account.
Still getting a connection error?
- Check that the user is added to the database with privileges in Manage My Databases.
- Check that you used the full prefixed names and the right password.
- For WordPress, see How to fix Error Establishing a Database Connection in WordPress?
Official documentation: cPanel Remote Database Access and cPanel Manage My Databases.