# User-level database connections (MySQL)

**URL:** <https://www.ruby-forum.com/t/user-level-database-connections-mysql/90897>\
**Category:** Rails\
**Created:** [April 2, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/user-level-database-connections-mysql/90897 "2007-04-02T20:52:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blakeage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@blakeage](https://www.ruby-forum.com/u/blakeage)\
**Post date:** [April 2, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/user-level-database-connections-mysql/90897/1 "2007-04-02T20:52:38Z")

</div>

Is there a way to have a user connect as themselves from Rails to MySQL,  
instead of connecting via the normal database.yml user? I’m trying to  
build in security at the database level, with Rails security on top.

Thanks

---

<div class="post-metadata">

**Author:** ![blakeage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@blakeage](https://www.ruby-forum.com/u/blakeage)\
**Post date:** [April 2, 2007, 9:34pm UTC](https://www.ruby-forum.com/t/user-level-database-connections-mysql/90897/2 "2007-04-02T21:34:50Z")

</div>

Blake M. wrote:

> Is there a way to have a user connect as themselves from Rails to MySQL,  
> instead of connecting via the normal database.yml user? I’m trying to  
> build in security at the database level, with Rails security on top.
> 
> Thanks

You want to allow different users connect to different database through  
a site?

Is that what you want?

Specific the security information through the site and not through the  
database.xml ?

If so you should try to look at establish\_connection() method 😃

---

<div class="post-metadata">

**Author:** ![blakeage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@blakeage](https://www.ruby-forum.com/u/blakeage)\
**Post date:** [April 2, 2007, 11:30pm UTC](https://www.ruby-forum.com/t/user-level-database-connections-mysql/90897/3 "2007-04-02T23:30:04Z")

</div>

Jamal S. wrote:

> You want to allow different users connect to different database through  
> a site?  
> No, different users, same database

> Specific the security information through the site and not through the  
> database.xml ?  
> Yes

> If so you should try to look at establish\_connection() method 😃  
> I looked into this as an option, but I have a hunch that an ActiveRecord  
> session (established through establish\_connection) is process or  
> application server wide, so it couldn’t be used unless each user had  
> their own process.

What I’m trying to do is create a connection to the database as a user  
(each user will have their own MySQL login that is generated from the  
website when they register). This way we can enforce create, read,  
update on specific tables priviledges at the database level, and can log  
changes “in their name”.
