Cannot Connect to MySQL on Port 3306

PHP/MariaDB/MySQL | Updated March 2026

If you're getting connection errors when trying to reach your MySQL or MariaDB database on port 3306, the issue is almost always a configuration problem rather than a port problem. On Ultra Web Hosting shared servers, the database server runs on the standard port 3306, but remote connections require explicit setup in cPanel. This guide walks through every common cause and fix.

01. Local vs Remote Connections

There are two types of MySQL connections, and they behave very differently on a shared hosting server:

Local connections - Your script and database are on the same server. The hostname is localhost and MySQL uses a Unix socket instead of TCP port 3306. This is the standard setup for WordPress, Joomla, and most CMS platforms hosted with us.

Remote connections - You're connecting from a different server, your home computer, or a third-party application like MySQL Workbench or Sequel Pro. These connections use TCP on port 3306 and require explicit setup in cPanel.

Tip

If your website and database are both hosted with Ultra Web Hosting, you should always use localhost as the database host. There is no reason to use a remote connection for a site running on the same server.

02. Common Causes of Connection Failures

Wrong Database Hostname

The most frequent cause. Your application config is using your domain name, server IP, or 127.0.0.1 instead of localhost. While 127.0.0.1 might seem equivalent, it forces a TCP connection instead of a socket connection, which can fail if the MySQL server is not listening on the loopback interface for your user.

Wrong Username or Password

Database usernames on cPanel servers are prefixed with your cPanel username. If your cPanel account is example and you created a database user called dbuser, the full username is example_dbuser. The same prefix applies to database names: example_dbname.

User Not Assigned to Database

Creating a user and creating a database are two separate steps. You must also assign the user to the database with the correct privileges. In cPanel, go to MySQL Databases, scroll to "Add User to Database," select both, and grant ALL PRIVILEGES.

Remote MySQL Not Enabled

If you're connecting from outside the server (MySQL Workbench, another server, a local development machine), you need to add your IP address in cPanel under Remote MySQL. Without this, the connection is refused at the firewall level before MySQL even sees it.

03. Checking Your Connection String

Here are the correct connection settings for scripts running on the same server:

Database Host: localhost
Database Name: cpaneluser_dbname
Database User: cpaneluser_dbuser
Database Password: (your password)
Port: 3306 (default, usually not needed when using localhost)

For WordPress, these are set in wp-config.php:

define('DB_NAME', 'cpaneluser_dbname');
define('DB_USER', 'cpaneluser_dbuser');
define('DB_PASSWORD', 'your_password_here');
define('DB_HOST', 'localhost');
Warning

Do not use DB_HOST values like mysql.yourdomain.com, yourdomain.com, or the server IP address for local connections. These will fail or create unnecessary network overhead. Always use localhost.

04. Enabling Remote MySQL Access

If you legitimately need to connect from outside the server (desktop database client, external application, another server), follow these steps:

  1. Log in to cPanel - Go to my.ultrawebhosting.com and click the cPanel button next to your hosting package
  2. Open Remote MySQL - Under the Databases section, click "Remote MySQL"
  3. Add your IP address - Enter your current public IP address. You can find it at tools.ultrawebhosting.com
  4. Click Add Host - The firewall rule takes effect within a few minutes

Once added, connect using your server's hostname (shown in your welcome email or cPanel left sidebar) as the database host, not localhost.

Tip

If your ISP assigns you a dynamic IP address, you may need to update the Remote MySQL entry periodically. Some clients use a percentage wildcard (e.g., 24.22.%) to cover a range, but this is less secure. A better approach is to use an SSH tunnel for remote database access.

05. Firewall and IP Considerations

Ultra Web Hosting servers run CSF (ConfigServer Security and Firewall) which blocks port 3306 by default for incoming connections. The Remote MySQL feature in cPanel creates a firewall exception for your specific IP address.

If you've added your IP to Remote MySQL and still can't connect, check these possibilities:

Your IP has changed - Residential ISPs frequently rotate IP addresses. Verify your current IP at tools.ultrawebhosting.com and compare it to what you entered in Remote MySQL.

Your IP was blocked by the firewall - Too many failed connection attempts (wrong password, wrong username) can trigger an automatic IP block. Check using our firewall unblock guide or use the Up or Down checker to verify the server is reachable.

Corporate or hotel firewalls - Some networks block outbound connections on port 3306. Try from a different network or use an SSH tunnel instead.

06. Testing Your Connection

You can test your database connection from within your hosting account using a simple PHP script. Upload this as dbtest.php to your public_html directory:

<?php
$host = 'localhost';
$user = 'cpaneluser_dbuser';
$pass = 'your_password';
$db   = 'cpaneluser_dbname';

$conn = new mysqli($host, $user, $pass, $db);

if ($conn->connect_error) {
    die('Connection failed: ' . $conn->connect_error);
}
echo 'Connected successfully to ' . $db;
$conn->close();
?>
Important

Delete dbtest.php immediately after testing. It contains your database credentials in plain text and is publicly accessible while it exists in public_html.

For more advanced connection testing from SSH, see our MySQL connection test guide.

Still Can't Connect?

If you've checked all of the above and still can't reach your database, open a support ticket and include the exact error message, the hostname you're using, and whether the connection is local or remote.

Open a Support Ticket

Quick Recap: Fixing MySQL Port 3306 Connections

  1. Use localhost - If your script and database are on the same server, the host must be localhost
  2. Check the full username - Database usernames are prefixed with your cPanel username (e.g., user_dbuser)
  3. Assign user to database - Creating the user and database separately is not enough; they must be linked with privileges
  4. Enable Remote MySQL - For external connections, add your IP in cPanel under Remote MySQL
  5. Verify your IP - Check your current IP at tools.ultrawebhosting.com and make sure it matches what's in Remote MySQL

Last updated March 2026 · Browse all PHP/MySQL articles

  • 157 Users Found This Useful

Was this answer helpful?

Related Articles

Increase PHP Memory

PHP/MySQL | Updated 2026 If your website shows a "Fatal error: Allowed memory size exhausted"...

Cannot Connect to MariaDB MySQL Database

PHP/MariaDB/MySQL | Updated March 2026 The "Could not connect to the database" error means...

Useful CSV to MySQL Script

PHP/MySQL | Updated 2026 Importing CSV data into a MySQL/MariaDB database is a common task...

How can I find my MariaDB - MySQL version?

PHP/MariaDB/MySQL | Updated March 2026 There are several ways to check your MariaDB/MySQL...

Server Paths - PHP Perl Python and More

PHP/MariaDB/MySQL | Updated March 2026 The default path to PHP on Ultra Web Hosting servers...



Save 30% on web hosting - Use coupon code Hosting30