# How to acces a MySQL table with ActiveRecord

**URL:** <https://www.ruby-forum.com/t/how-to-acces-a-mysql-table-with-activerecord/98541>\
**Category:** Ruby\
**Created:** [July 15, 2006, 8:22pm UTC](https://www.ruby-forum.com/t/how-to-acces-a-mysql-table-with-activerecord/98541 "2006-07-15T20:22:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsn1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@jsn1](https://www.ruby-forum.com/u/jsn1)\
**Post date:** [July 15, 2006, 8:22pm UTC](https://www.ruby-forum.com/t/how-to-acces-a-mysql-table-with-activerecord/98541/1 "2006-07-15T20:22:45Z")

</div>

# require AR

require ‘rubygems’  
require\_gem ‘activerecord’

ActiveRecord::Base.establish\_connection({  
:adapter =\> “mysql”,  
:database =\> “cocoa”,  
:socket =\> “/tmp/mysql.socket”,  
:username =\> ,  
:password =\>   
})

# define a simple model

class Task \< ActiveRecord::Base  
end

I am trying to run this script in ruby that reads a MySQL table, called  
Tasks, like in this example:

[http://wiki.rubyonrails.com/rails/pages/HowToUseActiveRecordOutsideRails](http://wiki.rubyonrails.com/rails/pages/HowToUseActiveRecordOutsideRails)

I got the following error message:  
irb(main):001:0\> Task.create “title” =\> “Item #1”  
NameError: uninitialized constant Task  
from (irb):1

---

<div class="post-metadata">

**Author:** ![jsn1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@jsn1](https://www.ruby-forum.com/u/jsn1)\
**Post date:** [July 16, 2006, 5:09pm UTC](https://www.ruby-forum.com/t/how-to-acces-a-mysql-table-with-activerecord/98541/2 "2006-07-16T17:09:30Z")

</div>

here is the solution:  
[http://vsbabu.org/mt/archives/2005/07/19/oracle\_with\_active\_record.html](http://vsbabu.org/mt/archives/2005/07/19/oracle_with_active_record.html)

Jose P. wrote:

> # require AR
> 
> require ‘rubygems’  
> require\_gem ‘activerecord’
> 
> ActiveRecord::Base.establish\_connection({  
> :adapter =\> “mysql”,  
> :database =\> “cocoa”,  
> :socket =\> “/tmp/mysql.socket”,  
> :username =\> ,  
> :password =\>   
> })
> 
> # define a simple model
> 
> class Task \< ActiveRecord::Base  
> end
> 
> I am trying to run this script in ruby that reads a MySQL table, called  
> Tasks, like in this example:
> 
> [Peak Obsession](http://wiki.rubyonrails.com/rails/pages/HowToUseActiveRecordOutsideRails)
> 
> I got the following error message:  
> irb(main):001:0\> Task.create “title” =\> “Item #1”  
> NameError: uninitialized constant Task  
> from (irb):1
