Hi ,
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.
- Verify
wp-config.php
File
Ensure the database connection details in your wp-config.php
file are correct:
- Database Name (
DB_NAME
): Ensure it matches the database you migrated. - Database User (
DB_USER
): Verify the username is valid and has the correct permissions for the database. - Database Password (
DB_PASSWORD
): Double-check the password for the database user. - Database Host (
DB_HOST
): Use the fully qualified domain name (FQDN) of the Azure MySQL server (e.g.,yourservername.mysql.database.azure.com
). Do not uselocalhost
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', '');
- Check Azure MySQL Server Settings
- Log into the Azure portal and navigate to your MySQL server.
- Verify Server Name: Ensure the FQDN matches what you entered in
DB_HOST
. - Networking:
- Check if the database is accessible from the VM/container where WordPress is hosted.
- Ensure the required IPs are added in the Firewall Rules of the MySQL server.
- If using Private Link, confirm that your WordPress application has access to the private endpoint.
- Authentication:
- Verify that the database user exists and is not locked.
- Use a MySQL client to test the connection manually
mysql -u your-username@your-server -p -h yourservername.mysql.database.azure.com
3.Ensure Correct PHP MySQL Extension
- Confirm that the required PHP extensions (
mysqli
orpdo_mysql
) are installed and enabled on your web server. You can check this by creating aphpinfo.php
file: <?php phpinfo(); ?> - Look for
mysqli
orpdo_mysql
in the output.
4.Update WordPress Database Table Permissions
- Use a MySQL client or tool (like MySQL Workbench or phpMyAdmin) to ensure that the user specified in
wp-config.php
has the correct permissions for the database. GRANT ALL PRIVILEGES ONyour-database-name
. TO 'your-username@your-server' IDENTIFIED BY 'your-password';* FLUSH PRIVILEGES;
5.Check for Configuration Caching
- Some web hosting or caching mechanisms might cache old configurations. Restart your web server (ex: Apache or Nginx) and PHP-FPM services. sudo systemctl restart apache2 sudo systemctl restart php7.x-fpm
6.Debug Database Connection
- Enable WordPress debug mode to get more detailed error messages: Add the following lines to your
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.