sp312 sp312 - 4 years ago 344
SQL Question

Wordpress unable to establish connection to mySQL database

I'm trying to set up a new wordpress site on my local server.
I've added the correct credentials in the config.php but when I try to begin the WP installation process I get the error message:

Warning: mysql_connect(): Access denied for user 'x'@'localhost' (using password: YES) in /home/httpd/html/xxx/public_html/wordpress/wp-includes/wp-db.php on line 1518

In wp-db.php line 1518 the code is:

$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );

I'm not sure what this error is telling me to fix. I tried actually writing the credentials in where it says dbhost, dbuser etc. Tried writing the credentials minus the password as some solutions has suggested but it still does not work.

Also granted all privileges to the user on the database but still same error message. If anyone can help that'd be great. Thanks.

Answer Source

In my humble opinion the problem is not in WP files, but it is in your DB server settings.

Create a file called test_connection.php and save it in the same folder of your wp installation (where you have your index).

In that file write the following code, save it and then launch it to test your connection to the database.

In the code just change USERNAME, PASSWORD and DB_NAME with yours.

UPDATE

<?php
header('Content-type: text/html; charset=utf-8');
$con = mysqli_connect("localhost","USERNAME","PASSWORD","DB_NAME");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  } else {
  echo "Ok, you're connected"; }
?>

This is the first test I suggest you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download