Error:
**Warning**: mysqli_real_connect(): (HY000/2002): Connection refused in **/home/gify.com.bd/public_html/wp-includes/class-wpdb.php** on line **1982**
`Connection refused`
# Error establishing a database connection
This either means that the username and password information in your `wp-config.php` file is incorrect or that contact with the database server at `localhost:3306` could not be established. This could mean your host’s database server is down.
- Are you sure you have the correct username and password?
- Are you sure you have typed the correct hostname?
- Are you sure the database server is running?
If you are unsure what these terms mean you should probably contact your host.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey there 👋,
This error means WordPress can’t connect to your MySQL database.
This can be caused by a few things, so you should check the following:
Check your wp-config.php
settings:
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_user');
define('DB_PASSWORD', 'your_database_password');
define('DB_HOST', 'localhost:3306');
Check your MySQL server status:
sudo systemctl status mysql
sudo systemctl start mysql
Verify your MySQL Credentials:
wp-config.php
while connected via SSH on your Droplet:
mysql -u your_database_user -p
wp-config.php
.Check MySQL logs:
sudo tail -f /var/log/mysql/error.log
Feel free to share the output of your logs and the MySQL service status!
Let me know how it goes or if you need more help troubleshooting!
- Bobby
Heya,
The “Connection refused” error you’re encountering in WordPress means that WordPress is unable to establish a connection to the MySQL database. Here’s a step-by-step approach to troubleshoot and resolve the issue:
Ensure that the MySQL service is running on your server. Run the following command to check the status:
sudo systemctl status mysql
If MySQL is not running, you can start it with:
sudo systemctl start mysql
wp-config.php
The error suggests that WordPress is unable to connect to the database due to incorrect credentials. Open the wp-config.php
file and verify that the database settings are correct:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' ); // Or your database host (e.g., 127.0.0.1)
Ensure that:
localhost
if MySQL is running on the same server. If you’re using a different port or external database, modify it accordingly (e.g., localhost:3306
or your_remote_host:port
).Try connecting to MySQL from the command line using the same credentials found in wp-config.php
:
mysql -u your_database_user -p your_database_name
If you can connect successfully, it means the credentials are correct. If not, double-check the username and password.
If your MySQL server is configured to listen only on certain IP addresses or not on localhost
, this could cause the issue. Open your MySQL configuration file (typically /etc/mysql/mysql.conf.d/mysqld.cnf
or /etc/my.cnf
) and check the following line:
bind-address = 127.0.0.1
Ensure the bind address is either set to 127.0.0.1
for local connections or commented out for all connections. Restart MySQL after changes:
sudo systemctl restart mysql
The “Connection refused” error indicates that your WordPress site cannot connect to the MySQL database. Here are some steps to troubleshoot and resolve the issue:
wp-config.php
FileOpen your wp-config.php
file (located in the root of your WordPress installation) and ensure the following values are correct:
/** The name of the database for WordPress */
define('DB_NAME', 'your_database_name');
/** MySQL database username */
define('DB_USER', 'your_database_user');
/** MySQL database password */
define('DB_PASSWORD', 'your_database_password');
/** MySQL hostname */
define('DB_HOST', 'localhost'); // This is often 'localhost', but it could be different for your host.
wp-config.php
file.localhost
, but some hosting providers use different settings (like an IP address or specific hostname).wp-config.php
. If you cannot connect, the credentials are likely incorrect.mysql -u your_database_user -p -h localhost
If you have access to error logs, check the logs for more detailed error messages. This can provide clues about what’s going wrong.
After going through these steps, if you’re still experiencing issues, it’s best to reach out to your hosting provider’s support team. They can provide more specific insights based on their server setup and logs.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.