简体   繁体   中英

MySQL database connection works on Live Server, but not on Test Server

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.

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; grant all privileges on * to user@localhost identified by 'password'; flush privileges;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM