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.
If your script is on the same server as your database, the hostname should be localhost, not your domain name or server IP. Using anything other than localhost tells MySQL to attempt a remote (TCP) connection, which will fail unless Remote MySQL is configured. Check your wp-config.php, connection script, or application config file and make sure DB_HOST is set to localhost.
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.
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');
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:
- Log in to cPanel - Go to my.ultrawebhosting.com and click the cPanel button next to your hosting package
- Open Remote MySQL - Under the Databases section, click "Remote MySQL"
- Add your IP address - Enter your current public IP address. You can find it at tools.ultrawebhosting.com
- 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.
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();
?>
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 TicketQuick Recap: Fixing MySQL Port 3306 Connections
- Use localhost - If your script and database are on the same server, the host must be
localhost - Check the full username - Database usernames are prefixed with your cPanel username (e.g.,
user_dbuser) - Assign user to database - Creating the user and database separately is not enough; they must be linked with privileges
- Enable Remote MySQL - For external connections, add your IP in cPanel under Remote MySQL
- 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
