An Azure service designed to help simplify, guide, and automate database migrations to Azure.
I got this error:
Warning: mysqli_real_connect(): (HY000/2002): Connection refused in /var/www/wordpress/wp-includes/class-wpdb.php on line 1987
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need some help with an issue I'm facing after migrating my WordPress site to Azure. Initially, everything worked fine after the migration, and the site was functioning using my migrated database credentials. However, after a few hours, I started getting the following error: Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/wordpress/wp-includes/class-wpdb.php on line 1982 When I checked the MySQL server, I couldn't find the server or user specified in the wp-config.php file. I tried updating the config file with a new Azure MySQL user and credentials, but it still doesn't work.__
Warning__: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/wordpress/wp-includes/class-wpdb.php on line 1982
No such file or directory
An Azure service designed to help simplify, guide, and automate database migrations to Azure.
An Azure managed MySQL database service for app development and deployment.
Locked Question. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
I got this error:
Warning: mysqli_real_connect(): (HY000/2002): Connection refused in /var/www/wordpress/wp-includes/class-wpdb.php on line 1987
Connection refusedHi ,
Thanks for reaching out to Microsoft Q&A.
The error Warning: mysqli_real_connect(): (HY000/2002): No such file or directory typically indicates that WordPress cannot connect to the MySQL DB server. This issue is common when migrating a WordPress site, especially if the database connection settings or environment configuration are not updated correctly.
wp-config.php FileEnsure the database connection details in your wp-config.php file are correct:
DB_NAME): Ensure it matches the database you migrated.DB_USER): Verify the username is valid and has the correct permissions for the database.DB_PASSWORD): Double-check the password for the database user.DB_HOST): Use the fully qualified domain name (FQDN) of the Azure MySQL server (e.g., yourservername.mysql.database.azure.com). Do not use localhost unless the database server is on the same VM/container.define('DB_NAME', 'your-database-name');
define('DB_USER', 'your-username@your-server');
define('DB_PASSWORD', 'your-password');
define('DB_HOST', 'yourservername.mysql.database.azure.com');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
DB_HOST. mysql -u your-username@your-server -p -h yourservername.mysql.database.azure.com
3.Ensure Correct PHP MySQL Extension
mysqli or pdo_mysql) are installed and enabled on your web server. You can check this by creating a phpinfo.php file: <?php phpinfo(); ?>mysqli or pdo_mysql in the output.4.Update WordPress Database Table Permissions
wp-config.php has the correct permissions for the database. GRANT ALL PRIVILEGES ON your-database-name. TO 'your-username@your-server' IDENTIFIED BY 'your-password';* FLUSH PRIVILEGES;5.Check for Configuration Caching
6.Debug Database Connection
wp-config.php file: define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); Check the debug log file (wp-content/debug.log) for detailed error information.Double-check that all the required database tables and data were migrated correctly. Ensure there are no issues with the database structure or table prefixes (ex:, wp_).
Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.