Troubleshooting WordPress Database Connection and Installation Errors
Content
Encountering errors during a WordPress installation can be a frustrating experience, especially when they involve the database. A successful installation hinges on a correct and stable connection between WordPress and your MySQL or MariaDB database. Based on community reports, this guide covers the most common database-related installation errors and how to resolve them.
Common Symptoms
Users often report one of the following issues when trying to install WordPress:
- A blank white screen during the installation process (often on step 2).
- The critical error: "Error establishing a database connection."
- Error messages stating that core tables like
wp_options"don't exist" even after entering database credentials. - The installation script fails to create any tables in the designated database.
- A database repair attempt fails because it cannot find the tables.
Why This Happens
These errors are almost always related to the connection between the WordPress files (PHP) and the database server (MySQL/MariaDB). The root cause is typically one of the following:
- Incorrect Database Credentials: The database name, username, password, or host defined in the
wp-config.phpfile are inaccurate. - Database User Privileges: The database user exists but has not been granted all necessary privileges (e.g., SELECT, INSERT, UPDATE, DELETE, CREATE, DROP) for the specific WordPress database.
- Remote Database Connection Issues: When the database is on a separate host (like Amazon RDS, Google Cloud SQL, or a different server on your network), firewalls, security groups, or network policies may be blocking the connection.
- Outdated PHP MySQL Extensions: Modern WordPress requires the
mysqliextension. If a PHP installation is misconfigured and using the oldmysql_connect()function, it will fail. - Socket Authentication (MySQL 8+): Some MySQL 8 installations default to using the
auth_socketplugin for user authentication, which is incompatible with WordPress. WordPress requires password-based authentication. - Corrupted File Permissions: The web server user (e.g.,
www-dataon Linux) does not have adequate read/write permissions on the WordPress directory or cannot execute PHP scripts properly.
How to Troubleshoot and Fix It
1. Verify Database Credentials and Connection
First, double-check the fundamentals. The values in your wp-config.php file must be perfect.
- Database Name: Ensure the database was created exactly as typed.
- Username & Password: Confirm the user was created and the password is correct. Avoid special characters that might need escaping.
- Database Host: For local installations, this is almost always
localhost. For remote databases, use the exact IP address or hostname provided by your hosting service.
Pro Tip: Test the connection from your web server using the command line. This isolates the problem from WordPress itself.
mysql -u YOUR_DATABASE_USERNAME -p -h YOUR_DATABASE_HOST
After entering the password, try to use the database:
USE YOUR_DATABASE_NAME;
If this command fails, the issue is with your database setup, not WordPress.
2. Check and Grant User Privileges
Creating a user and a database is not enough. The user must have full permissions for that database. Connect to MySQL as a root user and run the following commands, replacing database_user and database_name with your details:
GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost';
FLUSH PRIVILEGES;
If your database is on a separate host, use 'database_user'@'%' or a specific IP address instead of @'localhost'.
3. Configure Remote Database Security
If your database is remote (e.g., on Amazon RDS, Google Cloud SQL, or a different VPS), you must explicitly allow connections from your web server's IP address.
- AWS RDS: Modify the associated security group to allow inbound traffic on port 3306 from your EC2 instance's IP or security group.
- Google Cloud SQL: Add your Compute Engine VM's IP address to the authorized networks list for the database instance.
- General Firewalls: Ensure any firewalls (e.g.,
iptables,ufw) on the database server are configured to allow traffic on port 3306 from the web server's IP.
4. Enable Debugging to See the Real Error
A generic "critical error" or blank screen hides the true problem. Enable debugging in WordPress to see the specific error message.
Open your wp-config.php file (or create one from wp-config-sample.php) and add the following lines:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
This will create a debug.log file in the /wp-content/ directory containing detailed error messages. This log is invaluable for diagnosis. A common error found here is mysqli_real_connect(): (HY000/2002): Permission denied, which often points to a network or firewall issue.
5. Ensure mysqli PHP Extension is Active
WordPress requires the PHP mysqli extension. An error mentioning mysql_connect() is a clear sign this extension is missing. Check your PHP configuration.
- Run
php -mfrom the command line to list loaded modules and look formysqli. - On Ubuntu/Debian, install it with:
sudo apt-get install php-mysql - On Windows, ensure
extension=mysqliis uncommented in yourphp.inifile.
6. Switch from Socket to Password Authentication (MySQL 8)
If your MySQL 8 server uses auth_socket for user authentication, WordPress will be unable to connect. You must alter the user to use a password.
Log into MySQL as root and run:
ALTER USER 'your_wordpress_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_strong_password_here';
FLUSH PRIVILEGES;
Conclusion
Most WordPress installation failures related to databases are solvable by methodically checking the connection, credentials, and user permissions. The process involves working both in the database environment and the WordPress file system. By enabling debugging and verifying each step of the connection process, you can identify and resolve the underlying cause, leading to a successful installation.
Related Support Threads Support
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-971/
-
Installation with MSSQL DBhttps://wordpress.org/support/topic/installation-with-mssql-db/
-
WordPress could not establish a secure connection to WordPress.orghttps://wordpress.org/support/topic/wordpress-could-not-establish-a-secure-connection-to-wordpress-org-4/
-
Using Azure MySQL DB on a non Azure hosted WP Sitehttps://wordpress.org/support/topic/using-azure-mysql-db-on-a-non-azure-hosted-wp-site/
-
No DB connectivity on IIS 10https://wordpress.org/support/topic/no-db-connectivity-on-iis-10/
-
WordPress Error: Error establishing a database connectionhttps://wordpress.org/support/topic/wordpress-error-error-establishing-a-database-connection/
-
MySQL user can’t access database to install WordPresshttps://wordpress.org/support/topic/mysql-user-cant-access-database-to-install-wordpress/
-
Missing tableshttps://wordpress.org/support/topic/missing-tables-11/
-
Error establishing a db connection and http 500https://wordpress.org/support/topic/error-establishing-a-db-connection-and-http-500/
-
installing WP on WD Mycloud EX41https://wordpress.org/support/topic/installing-wp-on-wd-mycloud-ex41/
-
openSUSE Leap 15 error establishing db connecthttps://wordpress.org/support/topic/opensuse-leap-15-error-establishing-db-connect/
-
WP-CLI in Github Actions – “Error establishing a database connection.”https://wordpress.org/support/topic/wp-cli-in-github-actions-error-establishing-a-database-connection/
-
Install of WP fail using other than ‘root’ as db userhttps://wordpress.org/support/topic/install-of-wp-fail-using-other-than-root-as-db-user/
-
Installation error : Unkown column “wp_” in field listhttps://wordpress.org/support/topic/installation-error-unkown-column-wp_-in-field-list/
-
Installing WordPress on Windows 10 with manual MySQL installhttps://wordpress.org/support/topic/installing-wordpress-on-windows-10-with-manual-mysql-install/
-
WP 5 Minute Install Not Up To the Taskhttps://wordpress.org/support/topic/wp-5-minute-install-not-up-to-the-task/
-
Local Install Errorhttps://wordpress.org/support/topic/local-install-error/
-
Install WordPress with PostgreSQL as the DBhttps://wordpress.org/support/topic/install-wordpress-with-postgresql-as-the-db/
-
Error establishing database connectionhttps://wordpress.org/support/topic/error-establishing-database-connection-138/
-
Wp_options table not available…https://wordpress.org/support/topic/wp_options-table-not-available/
-
500 blank page wp-admin/install.php docker (php8,mysql,nginx)https://wordpress.org/support/topic/500-blank-page-wp-admin-install-php-docker-php8mysqlnginx/
-
Error establishing a database connection when I try to install wordpresshttps://wordpress.org/support/topic/error-establishing-a-database-connection-when-i-try-to-install-wordpress/
-
WordPress installation on windows -missing tableshttps://wordpress.org/support/topic/wordpress-installation-on-windows-missing-tables/
-
MariaDB authentication does not work when MariaDB is integrated with pam+ldaphttps://wordpress.org/support/topic/mariadb-authentication-does-not-work-when-mariadb-is-integrated-with-pamldap/
-
wordpress install hangs on step 2 with a blank screenhttps://wordpress.org/support/topic/wordpress-install-hangs-on-step-2-with-a-blank-screen/
-
Error establising a database connectionhttps://wordpress.org/support/topic/error-establising-a-database-connection-2/
-
Im facing alot of errors on linuxhttps://wordpress.org/support/topic/im-facing-alot-of-errors-on-linux/
-
Table doesn’t existhttps://wordpress.org/support/topic/table-doesnt-exist-10/
-
Mysql/Ubuntu helphttps://wordpress.org/support/topic/mysql-ubuntu-help/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-961/
-
How to Connect WordPress to MariaDB 10 & how to edit DB Table via WordPress?https://wordpress.org/support/topic/how-to-connect-wordpress-to-mariadb-10-how-to-edit-db-table-via-wordpress/
-
DB Issue on local install for Apple M1https://wordpress.org/support/topic/db-issue-on-local-install-for-apple-m1/
-
database error Unknowon column ‘wp_’ in ‘field list’ for query SELECT wp_https://wordpress.org/support/topic/database-error-unknowon-column-wp_-in-field-list-for-query-select-wp_/
-
Installing WP problem | List of wp tables doesn’t existhttps://wordpress.org/support/topic/installing-wp-problem-list-of-wp-tables-doesnt-exist/
-
Installing manually WordPress on Synology NAS DS1621+https://wordpress.org/support/topic/installing-manually-wordpress-on-synology-nas-ds1621/
-
Need help Installing WordPress on Windows Server 2008 R2https://wordpress.org/support/topic/need-help-installing-wordpress-on-windows-server-2008-r2-2/
-
weird installation database errorhttps://wordpress.org/support/topic/weird-installation-database-error/
-
Staging WP install without mySQLhttps://wordpress.org/support/topic/staging-wp-install-withour-mysql/
-
Mysql Doesnot create on staging sitehttps://wordpress.org/support/topic/mysql-doesnot-create-on-staging-site/
-
Connect to remote MariaDB using SSL or X509 certificate?https://wordpress.org/support/topic/connect-to-remote-mariadb-using-ssl-or-x509-certificate/
-
Error installing WordPresshttps://wordpress.org/support/topic/error-installing-wordpress-9/
-
Installation Error – FastCGI process exited unexpectedlyhttps://wordpress.org/support/topic/installation-error-fastcgi-process-exited-unexpectedly/
-
Error login mysql 5.7 auth_sockethttps://wordpress.org/support/topic/error-login-mysql-5-7-auth_socket/
-
New Self Hosted Install Database Connection Failshttps://wordpress.org/support/topic/new-self-hosted-install-database-connection-fails/
-
WordPress on IIS on Server 2019https://wordpress.org/support/topic/wordpress-on-iis-on-server-2019/
-
WordPress WP-config error.https://wordpress.org/support/topic/wordpress-wp-config-error/
-
DOA installationhttps://wordpress.org/support/topic/doa-3/
-
New Install Won’t Create Tableshttps://wordpress.org/support/topic/new-install-wont-create-tables-2/
-
WordPress Not Creating Tables In MySQLhttps://wordpress.org/support/topic/wordpress-not-creating-tables-in-mysql/
-
The SQL Code for Postmeta tablehttps://wordpress.org/support/topic/the-sql-code-for-postmeta-table/
-
Getting critical error just after the first stephttps://wordpress.org/support/topic/getting-critical-error-just-after-the-first-step/
-
trouble with mySQL 8 in IIS Windows Server 2016https://wordpress.org/support/topic/mysql-8-in-iis-window-server-needed/
-
Error whilst install.php: Table ‘wordpress.wp_options’ doesn’t existhttps://wordpress.org/support/topic/error-whilst-install-php-table-wordpress-wp_options-doesnt-exist/
-
Installing 2nd copy of wordpress w 2nd databasehttps://wordpress.org/support/topic/installing-2nd-copy-of-wordpress-w-2nd-database/
-
First time install issue: Error HY000/2002https://wordpress.org/support/topic/first-time-install-issue-error-hy000-2002/