MySQL connection details: host, port, socket and examples

For hosting customers · Updated 2026-10-29

On this page
  1. The details
  2. Examples
  3. Connecting from another computer
  4. Good to know
  5. Common questions

Websites and applications on your account connect to MySQL (MariaDB) on the same server.

The details

SettingValue
Hostlocalhost
Socket/run/mysqld/mysqld.sock
Port3306 (only needed for network connections)
Database namethe full name with your prefix, for example username_shop
Usernamethe full name with your prefix, for example username_shop
Passwordthe database user's password

Use localhost, not 127.0.0.1: database users are created for localhost, and localhost connects through the socket, which is also faster.

Examples

WordPress (wp-config.php):

define( 'DB_NAME', 'username_shop' );
define( 'DB_USER', 'username_shop' );
define( 'DB_PASSWORD', 'your-password' );
define( 'DB_HOST', 'localhost' );

PHP (PDO):

$pdo = new PDO('mysql:host=localhost;dbname=username_shop;charset=utf8mb4', 'username_shop', 'your-password');

Laravel (.env):

DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=username_shop
DB_USERNAME=username_shop
DB_PASSWORD=your-password

Node.js (mysql2):

const db = await mysql.createConnection({ socketPath: '/run/mysqld/mysqld.sock', user: 'username_shop', password: 'your-password', database: 'username_shop' });

Python (PyMySQL):

db = pymysql.connect(unix_socket='/run/mysqld/mysqld.sock', user='username_shop', password='your-password', database='username_shop')

Connecting from another computer

From your own computer or another server, use the server name shown on the Remote MySQL page and port 3306, after allowing your address there. See Remote MySQL.

Good to know

  • New databases use utf8mb4. Use charset=utf8mb4 in connection strings.
  • The MySQL Databases page shows the host at the top (Host: localhost).
  • For PostgreSQL, the host is localhost and the port 5432: see PostgreSQL databases.

Common questions

Which host do I enter when an installer asks for "Database host"?

localhost. Leave the port empty or at its default.

My app only accepts host and port. What do I enter?

Use the socket where possible. If the app cannot use a socket, ask your hosting provider, because a TCP connection to 127.0.0.1 can be refused for users made for localhost.

Was this article helpful?

Still stuck?

Ask the AI about your exact situation — it answers from this knowledge base — or contact us.