Title: Error establishing database connection
Last modified: October 25, 2022

---

# Error establishing database connection

 *  [angelax](https://wordpress.org/support/users/angelax/)
 * (@angelax)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-138/)
 * I had a working WordPress installation on my own self-managed server. I ended
   up doing a fresh OS installation (Ubuntu Server 22.04) after backing up all files
   and databases. I freshly installed apache, MariaDB (version 10.6.7), php (version
   8.1.2), and php-mysql. I restored existing databases, including my WordPress 
   database, from the backups. I created database users with the same names and 
   same permissions as before. I tested logging in with the WordPress database user
   and password from the command line. I set up ufw as before, double checking that
   access to port 3306 is permitted from 127.0.0.1.
 * I followed the [WordPress installation instructions here](https://wordpress.org/support/article/how-to-install-wordpress/).
    1.  Downloaded latest version of WordPress and unpacked on server. Moved to appropriate
       folder `/var/www/html`
    2.  Restored database from backup, as mentioned above.
    3.  I ran the installation script at `http://example.com/wp-admin/install.php`
    4.  I entered my database name, db username, and db password, which were all tested
       on the command line to ensure correctness. I’ve tried both `localhost` and `
       127.0.0.1` in the host field and confirmed that my database table prefix is,
       in fact, the default `wp_`.
 * I’ve done a ridiculous amount of Googling and searching these forums and I’m 
   at a loss. I can’t get past the “Error establishing database connection” error
   message. I’ve also tried manually editing `wp-config.php` and that has the same
   result.
 * I’ve consulted the [guide to moving WordPress between servers](https://wordpress.org/support/article/moving-wordpress/),
   to make sure I didn’t do steps out of order. Since my domain and all file paths
   are exactly the same, I’m not seeing any explanation there.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [ivahyael](https://wordpress.org/support/users/ivahyael/)
 * (@ivahyael)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-138/#post-16130969)
 * Hi,
 * Do more details show when enabling debugging on your wp-config.php? If so, what
   do you see? You can paste this on your config file:
 *     ```
       define( 'WP_DEBUG', true );
       define( 'WP_DEBUG_DISPLAY', true);
       define( 'WP_DEBUG_LOG', true );
       ```
   
 * And then check your site once more, it should indicate which connection is exactly
   not matching your database and your WordPress configuration.
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [3 years, 5 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-138/#post-16132262)
 * see if this helps; [https://stackoverflow.com/questions/50037975/wordpress-cannot-connect-to-mysql-server](https://stackoverflow.com/questions/50037975/wordpress-cannot-connect-to-mysql-server)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Error establishing database connection’ is closed to new replies.

## Tags

 * [database connection](https://wordpress.org/support/topic-tag/database-connection/)
 * [Fresh Installation](https://wordpress.org/support/topic-tag/fresh-installation/)
 * [server migration](https://wordpress.org/support/topic-tag/server-migration/)

 * In: [Installing WordPress](https://wordpress.org/support/forum/installation/)
 * 2 replies
 * 3 participants
 * Last reply from: [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * Last activity: [3 years, 5 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-138/#post-16132262)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
