WordPress Website MySQL connection Problem

Centos VPS running Mysql 5.1

1 site running perfectly under an SQL account created when the site was built.

Created a new database with a new account and gave the account full privileges. Then installed WordPress and got the cannot connect to database error.

Then I created a new user, and also gave it access to the new database, same issue.

Then tried to use the account that works on the perfectly working site, and then get an issue saying “cannot select database”. Gave a working user account full privileges on new database and then get the “cannot connect to database error”

Logging into the VPS I can connect to MySql and create tables in the database will all users created. It appears to be an issue with the websites or PHP connecting to the databases?
LVL 58
Pete LongTechnical ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
... or a configuration issue on wordpress.

If you can logon to the databases concerned with the user accounts you have created and perform all the various operations then the problem is configuration.

Either the user / password / database / host / port combination in your WP config has not been properly updated.

Here is a script you can use to test connectivity to your database - change the host / user / pass / database and port params as required.

Save this to the root of your wordpress web folder as say contest.php and then call it through your browser

define('gb_server', 'hostname');
define('gb_dbport', 3306);

echo "Testing with legacy MySQL lib ... <br/>";

$start = microtime(true);
$connection = mysql_connect(gb_server, gb_user, gb_password);
mysql_select_db(gb_database) or die( "Unable to select database");
$end = microtime(true);
echo "Total time (" . ($end - $start) . ")<br/>";

echo "Testing with MySQLi lib ... <br/>";
$start = microtime(true);
$connection = mysqli_connect(gb_server, gb_user, gb_password, gb_database, gb_dbport);

$end = microtime(true);
echo "Total time (" . ($end - $start) . ")<br/>";

Open in new window

If this works then the problem is your WP config if it does not the problem is your connection parameters.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pete LongTechnical ConsultantAuthor Commented:


Testing with legacy MySQL lib ... 
Unable to select database

Open in new window

BUT using the same code in a known good working Wordpress site on the same VPS returns the same error?

I'm using  

define('gb_server', 'localhost');

Open in new window

Is that the problem?

Bear in mind the main wordpress site is up and had been running for  along time this is a new (additional) site on the same server
Actually testing the account with new credentials now gives a response time with your script however the WP install still gives a cannot connect to DB error.

Just created another site , non worpdress, that is a basic script that calls a DB, it alsop gets a response however when you try and access the db through the site it fails.

Something strange is going on as PHP appears to log in.
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

Julian HansenCommented:
The problem is your credential - if the contest.php fails then the credentials you are giving it (user / pass / host / database) are incorrect.

If you can get contest.php to work then use the same credentials for your WP config and that should solve the problem.

The key thing is to eliminate variables from the equation. To do that first establish what the correct database connection parameters are and verify they work - that is what the test script is for. Once you have verified those the rest will follow.
Julian HansenCommented:
Something strange is going on as PHP appears to log in.
This is a misnomer - PHP has nothing to do with the process - if the creds are wrong the connection cannot be made - ultimately issues like this turn out to be finger trouble somewhere along the line.
I actually found out what was wrong, I believe I had 2 issues....

You are correct that the credentials were wrong, I changed them but it did not works still..

the reason APC cache, even though I had noti installed it for this site it had cached them on this virtual host! simply flushed the cache and away it went...thanks!!

My only issue now is another site I tested has the same issue with just a white screen , however I think that is a PHP issue.
Julian HansenCommented:
however I think that is a PHP issue.
That is probably because PHP has an error and error reporting is suppressed.

Turn errors on or if your ISP supports it check for an error log file to find out what the error is.

If you don't solve it - I recommend you open another question

You seem to be operating with two accounts - is that correct?
No Pete is a colleagure of mine who asked the question, he is not available now so I im using my account. He will mark it as answered on hiseturn :)
Pete LongTechnical ConsultantAuthor Commented:
Don't Panic! I asked the Question for my colleague :) (he had no Q points left)

You Sorted now Al?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.