PDOException: SQLSTATE[42000] [1044] Access denied for user 'lacare_d7'@'localhost' to database.

I got the following error when i cloned my database to a new one with a different name. I tried to reconnect my application tier to the new renamed database, it gave me the error as below.

"PDOException: SQLSTATE[42000] [1044] Access denied for user 'lacare_d7'@'localhost' to database 'lacare_d7_staging' in lock_may_be_available() (line 167 of /var/www/staging/html/includes/lock.inc)."

Since I have root account for this mysql server, I log in and ran successfully the following command:

mysql>  GRANT ALL PRIVILEGES ON lac2014_staging TO 'lac2014'@'localhost';
Query OK, 0 rows affected (0.00 sec)

It doesn't make any difference. Then I checked the file mentioned on the error message:
/var/www/staging/html/includes/lock.inc

got the 167th line as below:

155 /**
    156  * Check if lock acquired by a different process may be available.
    157  *
    158  * If an existing lock has expired, it is removed.
    159  *
    160  * @param $name
    161  *   The name of the lock.
    162  *
    163  * @return
    164  *   TRUE if there is no lock or it was removed, FALSE otherwise.
    165  */
    166 function lock_may_be_available($name) {
    167   $lock = db_query('SELECT expire, value FROM {semaphore} WHERE name = :name', array(':name' => $name))->fetchAssoc();
    168   if (!$lock) {
    169     return TRUE;
    170   }
    171   $expire = (float) $lock['expire'];
    172   $now = microtime(TRUE);
    173   if ($now > $expire) {
    174     // We check two conditions to prevent a race condition where another
    175     // request acquired the lock and set a new expire time. We add a small
    176     // number to $expire to avoid errors with float to string conversion.
    177     return (bool) db_delete('semaphore')
    178       ->condition('name', $name)
    179       ->condition('value', $lock['value'])
    180       ->condition('expire', 0.0001 + $expire, '<=')
    181       ->execute();
    182   }
    183   return FALSE;

Open in new window




Please help me with this hard issue.
Jason YuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Jason YuAuthor Commented:
Here is the copy screen of the error message.
database-connection-error.png
jimyXCommented:
You forgot to specify the tables of the DB to be included with "Db.*":
mysql>  GRANT ALL PRIVILEGES ON lac2014_staging.* TO 'lac2014'@'localhost';

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
Jason YuAuthor Commented:
Great, it is working now.

Why my "grant all" command didn't take effect on the tables belong to the "lac2014_staging" database.


mysql>  GRANT ALL PRIVILEGES ON lac2014_staging TO 'lac2014'@'localhost';
Query OK, 0 rows affected (0.00 sec)
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

jimyXCommented:
Since you did not specify any table then user was not granted permission to work on any table and hence no access to any data.

So you have to explicitly name the DBs and the tables that you are giving to any user. This is useful when you want to give only some particular tables under any database. If you want to give all then you use DB.*, or if all dbs and all tables then *.*.
Jason YuAuthor Commented:
Thank you very much, i appreciate your help.

If I want to read more materials and be a MYSQL dba, where is a good begining?

thanks.
Jason YuAuthor Commented:
Very good answer, spot the error.
jimyXCommented:
> If I want to read more materials and be a MYSQL dba, where is a good begining?

Nothing is better than a good book. There are plenty of free books online.
Also you can read MySQL Reference Manual, it has a lot of information that helps.
And if you read something, in a book or online, and it does not look clear, Google is your friend. You will get tons of explanations and examples.

But reading a book is much better for covering many aspects in an organized way.
Jason YuAuthor Commented:
thank you for your instruction, I will begin from this document.
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
MySQL Server

From novice to tech pro — start learning today.