# Database cookbook: database\_user resource: grant action uses table specified in previous resource def

**URL:** <https://discourse.chef.io/t/database-cookbook-database-user-resource-grant-action-uses-table-specified-in-previous-resource-def/3916>\
**Category:** Chef Infra (archive)\
**Created:** [May 7, 2013, 5:56pm UTC](https://discourse.chef.io/t/database-cookbook-database-user-resource-grant-action-uses-table-specified-in-previous-resource-def/3916 "2013-05-07T17:56:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmocek](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pmocek](https://discourse.chef.io/u/pmocek)\
**Post date:** [May 7, 2013, 5:56pm UTC](https://discourse.chef.io/t/database-cookbook-database-user-resource-grant-action-uses-table-specified-in-previous-resource-def/3916/1 "2013-05-07T17:56:49Z")

</div>

I believe I have discovered a bug in some combination of the database  
cookbook  
and the mysql cookbook. I’ll file a report with with Opscode unless  
another  
subscriber convinces me that my experience is a result of user error.

I define two databases and two database users. I grant all privileges  
on the  
first database to the first user, and all privileges on the second  
database to  
the second user. Additionally, I grant select on the time\_zone table of  
the  
mysql database to the first user. This triplet works or fails depending  
on the  
order of the database\_user resource definitions in my recipe. It  
appears as  
though my providing a table parameter for the second definition results  
in it  
"sticking" for the third.

In short, I get either this (good):

1. grant all on db1 to user1 = GRANT all ON db1.\* TO  
user1
2. grant all on db2 to user2 = GRANT all ON db2.\* TO  
user2
3. grant select on mysql.time\_zone to user1 = GRANT select ON  
mysql.time\_zone TO user1

or this (bad):

1. grant all on db1 to user1 = GRANT all ON db1.\* TO  
user1
2. grant select on mysql.time\_zone to user1 = GRANT select ON  
mysql.time\_zone TO user1
3. grant all on db2 to user2 = GRANT all ON  
db2.time\_zone TO user2

## works as expected

database\_user node[‘mycoobook’][‘db1’][‘user’] do  
provider Chef::Provider::Database::MysqlUser  
connection dbms\_connection\_info  
database\_name node[‘mycoobook’][‘db1’][‘schema’]  
host '%'  
privileges [:all]  
action :grant  
end

database\_user node[‘mycoobook’][‘db2’][‘user’] do  
provider Chef::Provider::Database::MysqlUser  
connection dbms\_connection\_info  
database\_name node[‘mycoobook’][‘db2’][‘schema’]  
host '%'  
privileges [:all]  
action :grant  
end

database\_user node[‘mycoobook’][‘db1’][‘user’] do  
provider Chef::Provider::Database::MysqlUser  
connection dbms\_connection\_info  
database\_name 'mysql’  
table 'time\_zone’  
host '%'  
privileges [:select]  
action :grant  
end

[2013-05-01T17:45:41+00:00] INFO: Processing database\_user[my\_db\_user1]  
action grant (mycoobook::dbms line 74)  
[2013-05-01T17:45:41+00:00] INFO: database\_user[my\_db\_user1]: granting  
access with statement [GRANT all ON first\_db.\* TO ‘my\_db\_user1’@’%‘  
IDENTIFIED BY ‘my\_password’]  
[2013-05-01T17:45:41+00:00] INFO: Processing database\_user[my\_db\_user2]  
action grant (mycoobook::dbms line 83)  
[2013-05-01T17:45:41+00:00] INFO: database\_user[my\_db\_user2]: granting  
access with statement [GRANT all ON second\_db.\* TO ‘my\_db\_user2’@’%‘  
IDENTIFIED BY ‘my\_password’]  
[2013-05-01T17:45:41+00:00] INFO: Processing database\_user[my\_db\_user1]  
action grant (mycoobook::dbms line 92)  
[2013-05-01T17:45:41+00:00] INFO: database\_user[my\_db\_user1]: granting  
access with statement [GRANT select ON mysql.time\_zone TO  
’my\_db\_user1’@’%’ IDENTIFIED BY ‘my\_password’]

## third grant faulty

database\_user node[‘mycoobook’][‘db1’][‘user’] do  
provider Chef::Provider::Database::MysqlUser  
connection dbms\_connection\_info  
database\_name node[‘mycoobook’][‘db1’][‘schema’]  
host '%'  
privileges [:all]  
action :grant  
end

database\_user node[‘mycoobook’][‘db1’][‘user’] do  
provider Chef::Provider::Database::MysqlUser  
connection dbms\_connection\_info  
database\_name 'mysql’  
table 'time\_zone’  
host '%'  
privileges [:select]  
action :grant  
end

database\_user node[‘mycoobook’][‘db2’][‘user’] do  
provider Chef::Provider::Database::MysqlUser  
connection dbms\_connection\_info  
database\_name node[‘mycoobook’][‘db2’][‘schema’]  
host '%'  
privileges [:all]  
action :grant  
end

[2013-05-01T17:57:47+00:00] INFO: Processing database\_user[my\_db\_user1]  
action grant (mycoobook::dbms line 74)  
[2013-05-01T17:57:47+00:00] INFO: database\_user[my\_db\_user1]: granting  
access with statement [GRANT all ON first\_db.\* TO ‘my\_db\_user1’@’%‘  
IDENTIFIED BY ‘my\_password’]  
[2013-05-01T17:57:47+00:00] INFO: Processing database\_user[my\_db\_user1]  
action grant (mycoobook::dbms line 83)  
[2013-05-01T17:57:47+00:00] INFO: database\_user[my\_db\_user1]: granting  
access with statement [GRANT select ON mysql.time\_zone TO  
’my\_db\_user1’@’%’ IDENTIFIED BY ‘my\_password’]  
[2013-05-01T17:57:47+00:00] INFO: Processing database\_user[my\_db\_user2]  
action grant (mycoobook::dbms line 93)  
[2013-05-01T17:57:47+00:00] INFO: database\_user[my\_db\_user2]: granting  
access with statement [GRANT all ON second\_db.time\_zone TO  
’my\_db\_user2’@’%’ IDENTIFIED BY ‘my\_password’]

–  
Phil Mocek  
[http://mocek.org](http://mocek.org)
