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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
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:Check your MySQL server status:
Verify your MySQL Credentials:
wp-config.php
while connected via SSH on your Droplet:wp-config.php
.Check MySQL logs:
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:
1. Check MySQL Service Status
Ensure that the MySQL service is running on your server. Run the following command to check the status:
If MySQL is not running, you can start it with:
2. Verify Database Credentials in
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: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
oryour_remote_host:port
).3. Test the MySQL Connection from the Command Line
Try connecting to MySQL from the command line using the same credentials found in
wp-config.php
:If you can connect successfully, it means the credentials are correct. If not, double-check the username and password.
4. Check MySQL Host Configuration
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: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: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:
1. Check Your
wp-config.php
FileOpen your
wp-config.php
file (located in the root of your WordPress installation) and ensure the following values are correct:2. Verify Database Credentials
wp-config.php
file.3. Check Database Hostname
localhost
, but some hosting providers use different settings (like an IP address or specific hostname).4. Test Database Server
wp-config.php
. If you cannot connect, the credentials are likely incorrect.5. Ensure MySQL Server is Running
6. Firewall and Security Settings
7. Check for Server Resource Limits
8. Debugging
If you have access to error logs, check the logs for more detailed error messages. This can provide clues about what’s going wrong.
Conclusion
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.