# GRANT: help me!

**URL:** <https://www.ruby-forum.com/t/grant-help-me/149434>\
**Category:** Rails\
**Created:** [September 24, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/grant-help-me/149434 "2008-09-24T20:55:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 24, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/grant-help-me/149434/1 "2008-09-24T20:55:17Z")

</div>

I have a database with grants commands setted (for admin, user, …).  
How can I connect each users with database (according with db rules) in  
rails?  
When rails application start it is connected according database.yml…  
but I need a right connection based on user type!

Thanks!!

---

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 24, 2008, 9:59pm UTC](https://www.ruby-forum.com/t/grant-help-me/149434/2 "2008-09-24T21:59:40Z")

</div>

I’m not sure I understand the question.

Are you talking about authenticating a users connection to the  
database inside your application?

If so that has nothing todo with the rails database connection. You  
need to lookinto a plugin that will do authentication and  
authorization on the rails application side…

OR

You want to lock down the access that you application has to the  
database?

GRANT SELECT,DROP ON app\_production.\* TO ‘someuser’@‘somewhere’  
IDENTIFIED BY ‘somepassword’;

That gives someuser connecting from host somwhere SELECT and DROP  
access to the app\_production database with the password  
somepassword ???

Does that answer your question or am I way off?

---

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 24, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/grant-help-me/149434/3 "2008-09-24T22:27:30Z")

</div>

> Are you talking about authenticating a users connection to the  
> database inside your application?
> 
> If so that has nothing todo with the rails database connection. You  
> need to lookinto a plugin that will do authentication and  
> authorization on the rails application side…
> 
> OR
> 
> You want to lock down the access that you application has to the  
> database?
> 
> GRANT SELECT,DROP ON app\_production.\* TO ‘someuser’@‘somewhere’  
> IDENTIFIED BY ‘somepassword’;
> 
> That gives someuser connecting from host somwhere SELECT and DROP  
> access to the app\_production database with the password  
> somepassword ???
> 
> Does that answer your question or am I way off?

I’ve grant commands setted into database (with GRANT SELECT…), 3  
grant (for 3 user types).  
For ex, if you are connetted to [Log In ‹ myhost.com — WordPress](http://myhost.com/admin), you will be prompted  
for insert your account information and rails will be connected to  
database with “admin” user… nothing more, nothing less 😉 .  
I know that this don’t sound good, but I can’t modify my db… and db  
have grants and views…  
If there are some trick to avoid this…

Thank you

---

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 25, 2008, 1:38am UTC](https://www.ruby-forum.com/t/grant-help-me/149434/4 "2008-09-25T01:38:00Z")

</div>

On Sep 25, 4:27 am, Al Shox [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > database?  
> > I’ve grant commands setted into database (with GRANT SELECT…), 3  
> > Posted viahttp://www.ruby-forum.com/.  
> > Something like this?

ActiveRecord::Base.establish\_connection(  
:adapter =\> “mysql”,  
:host =\> “localhost”,  
:username =\> “admin”,  
:password =\> “password”,  
:database =\> “database”  
)

---

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 25, 2008, 2:03am UTC](https://www.ruby-forum.com/t/grant-help-me/149434/5 "2008-09-25T02:03:01Z")

</div>

Erol F. wrote:

> On Sep 25, 4:27ï¿½am, Al Shox [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > database?  
> > > I’ve grant commands setted into database (with GRANT SELECT…), 3  
> > > Posted viahttp://www.ruby-forum.com/.  
> > > Something like this?
> 
> ActiveRecord::Base.establish\_connection(  
> :adapter =\> “mysql”,  
> :host =\> “localhost”,  
> :username =\> “admin”,  
> :password =\> “password”,  
> :database =\> “database”  
> )

(I’ve hear about it but…)  
You think that I need to create a “singleton” class that have “n”  
instances of database?? It’s the only solution??

Please help me with code samples!! This isn’t a trivial project and I  
need something concrete, otherwise I need to take another language  
solutions… and I really don’t want!!

---

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 25, 2008, 12:08pm UTC](https://www.ruby-forum.com/t/grant-help-me/149434/6 "2008-09-25T12:08:42Z")

</div>

Erol F. wrote:

> On Sep 25, 8:03ï¿½am, Al Shox [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > ï¿½ :username =\> “admin”,  
> > > solutions… and I really don’t want!!  
> > > –  
> > > Posted viahttp://www.ruby-forum.com/.
> 
> Not necessarily. How many kinds of db user accounts do you have? Are  
> they fixed, or do you have a variable number of them?

Three db accounts, and they are fixed.

---

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 25, 2008, 3:28am UTC](https://www.ruby-forum.com/t/grant-help-me/149434/7 "2008-09-25T03:28:34Z")

</div>

On Sep 25, 8:03 am, Al Shox [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > :username =\> “admin”,  
> > solutions… and I really don’t want!!  
> > –  
> > Posted viahttp://www.ruby-forum.com/.

Not necessarily. How many kinds of db user accounts do you have? Are  
they fixed, or do you have a variable number of them?

---

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 25, 2008, 12:21pm UTC](https://www.ruby-forum.com/t/grant-help-me/149434/8 "2008-09-25T12:21:03Z")

</div>

On Sep 25, 6:08 pm, Al Shox [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## Three db accounts, and they are fixed.
> 
> Posted viahttp://www.ruby-forum.com/.

You might want to try Dr. Nic’s Magic Multi-Connections to make the  
job easier.

[http://magicmodels.rubyforge.org/magic\_multi\_connections/](http://magicmodels.rubyforge.org/magic_multi_connections/)

---

<div class="post-metadata">

**Author:** ![zarabadoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zarabadoo](https://www.ruby-forum.com/u/zarabadoo)\
**Post date:** [September 25, 2008, 12:28pm UTC](https://www.ruby-forum.com/t/grant-help-me/149434/9 "2008-09-25T12:28:47Z")

</div>

> You might want to try Dr. Nic’s Magic Multi-Connections to make the  
> job easier.

Nice name anyway 😉

> [http://magicmodels.rubyforge.org/magic\_multi\_connections/](http://magicmodels.rubyforge.org/magic_multi_connections/)

I’ll going to see…

Thanks!
