Reputation: 627
I have a peculiar situation where the database connection works on the live server but not on my local computer.
I have the following connection script to access the database on both my local computer (running WAMP) as well as the live server:
function GetGlobalConnectionOptions()
{
return array(
'server' => 'localhost',
'port' => '3306',
'username' => 'sample_username',
'password' => 'sample_password',
'database' => 'sample_database'
);
I can connect to the live server database just fine. However, I'm not able to connect to the localhost database on my test computer. Here is the error I receive:
Could not connect to localhost:
Access denied for user ''@'localhost' to database 'sample_database'
I don't understand how it won't work on my localhost. Also, I'm concerned that it is saying the user is ''@'localhost' instead of sample_username@localhost. Possibly that is part of the issue, but I'm stuck. Any suggestions would be greatly appreciated.
FYI I have both usernames set up in each database with all privileges granted.
Upvotes: 0
Views: 1857
Reputation: 1877
In standard installations the users on localhost have to have explicit grants. So it does not suffice that user@% has access, it has to be user@localhost
. As admin, enter grant all privileges on * to user@localhost identified by 'password'; flush privileges;
Upvotes: 1