wp core install database connection error

First ensure the normal browser install works. If not, here’s a really good article on that: How to Fix the Error Establishing a Database Connection in WordPress.

Next thing to note is that your database may not be hosted on localhost. Then try to create the wp-config.php using 127.0.0.1 or 127.0.0.1:8889 (for MAMP for example) or something similar. On an existing installation this can be fixed by replacing the DB_HOST with define('DB_HOST', '127.0.0.1:8889'); in your wp-config.php.

For an existing site you could also try it with define('WP_ALLOW_REPAIR', true); in your wp-config.php and then access the site in a browser to let WordPress fix some common database issues for you.

The article also suggest to create a raw testconnection.php file in your WordPress root (replaced the database credentials with yours) and call that in a browser http://example.com/testconnection.php to see what will be returned:

<?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
  die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>

Leave a Comment