MySQL Hostname for Local and Remote Connections Print

  • 0

Overview

When connecting to your MySQL database, the hostname you use depends on where the connection is coming from either within your hosting account or from an external server.

Local Connections (Same Hosting Account)

If your application or script (such as PHP) is running on the same hosting account, you can use:

  • Hostname: localhost

This is the default setting and allows fast, internal communication with the database server.

Remote Connections (External Access)

If you are connecting from an external server or application, you must:

  1. Allow the remote IP address in cPanel using the Remote MySQL® feature. See the instructions in our Remote Mysql Tutorial.

  2. Use your domain name or server IP address as the hostname instead of localhost.

Summary

  • Use localhost for connections within the same hosting account.

  • Use your domain or server IP for remote connections.

  • Always whitelist external IPs before attempting remote access.


Was this answer helpful?
Back