# problem using mysql 5.1 with RoR 3.1

**URL:** <https://discuss.rubyonrails.org/t/problem-using-mysql-5-1-with-ror-3-1/60820>\
**Category:** rubyonrails-talk\
**Created:** [September 10, 2011, 10:16pm UTC](https://discuss.rubyonrails.org/t/problem-using-mysql-5-1-with-ror-3-1/60820 "2011-09-10T22:16:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nara](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@Nara](https://discuss.rubyonrails.org/u/Nara)\
**Post date:** [September 10, 2011, 10:16pm UTC](https://discuss.rubyonrails.org/t/problem-using-mysql-5-1-with-ror-3-1/60820/1 "2011-09-10T22:16:17Z")

</div>

I am newbie, and setup RoR 3.1 on Ubuntu 11.04. I followed everything on this blog, and the initial site came up fine on sqlite3:

> **[Ruby on Rails 3 and MySQL on Ubuntu 10.10](https://excid3.com/blog/ruby-on-rails-3-and-mysql-on-ubuntu-10-10/)**
>
> Ruby on Rails has become my favorite web framework recently. The sheer speed factor of development is incredible, and once you get past the learning curve, y...

Switching to mysql and running the rails server (rails s) displays this issue: ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):

I am pretty sure the database.yml is correct (shown later), that the database exists, and the user nara (myself) can access the database using the mysql client. I have tried rebooting my machine, but that does not help.

Any ideas? Nara

development: &nbsp;&nbsp;adapter: mysql2 &nbsp;&nbsp;encoding: utf8 &nbsp;&nbsp;reconnect: false &nbsp;&nbsp;database: mblogdev &nbsp;&nbsp;pool: 5 &nbsp;&nbsp;username: nara &nbsp;&nbsp;password: \<right-password\> &nbsp;&nbsp;socket: /var/run/mysqld/mysqld.sock

# Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: &nbsp;&nbsp;adapter: mysql2 &nbsp;&nbsp;encoding: utf8 &nbsp;&nbsp;reconnect: false &nbsp;&nbsp;database: mblogtest &nbsp;&nbsp;pool: 5 &nbsp;&nbsp;username: nara &nbsp;&nbsp;password: \<right-password\> &nbsp;&nbsp;socket: /var/run/mysqld/mysqld.sock

production: &nbsp;&nbsp;adapter: mysql2 &nbsp;&nbsp;encoding: utf8 &nbsp;&nbsp;reconnect: false &nbsp;&nbsp;database: mblogprod &nbsp;&nbsp;pool: 5 &nbsp;&nbsp;username: root &nbsp;&nbsp;password: &nbsp;&nbsp;socket: /var/run/mysqld/mysqld.sock

---

<div class="post-metadata">

**Author:** ![Nara](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@Nara](https://discuss.rubyonrails.org/u/Nara)\
**Post date:** [September 12, 2011, 7:42pm UTC](https://discuss.rubyonrails.org/t/problem-using-mysql-5-1-with-ror-3-1/60820/2 "2011-09-12T19:42:58Z")

</div>

I also gem installed mysql, and changed everything in database.yml to mysql. Still the same issue with ActiveRecord failing to connect. I will go back to using mysql2, and hopefully, get some help on this group. I will also try the mysql blog author at excid3.com. If I can somehow get mysql2 to work, I will post here. At this rate, it looks like I may have to try postgres instead.

Thanks Nara

---

<div class="post-metadata">

**Author:** ![Greg\_Reinacker](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@Greg\_Reinacker](https://discuss.rubyonrails.org/u/Greg_Reinacker)\
**Post date:** [September 12, 2011, 8:03pm UTC](https://discuss.rubyonrails.org/t/problem-using-mysql-5-1-with-ror-3-1/60820/3 "2011-09-12T20:03:09Z")

</div>

Don't know if it will help, but try something like

development: &nbsp;&nbsp;adapter: mysql2 &nbsp;&nbsp;encoding: utf8 &nbsp;&nbsp;database: mblogdev &nbsp;&nbsp;username: nara &nbsp;&nbsp;password: \<right-password\> &nbsp;&nbsp;host: server\_ip\_addr\_here

-GR

---

<div class="post-metadata">

**Author:** ![hassan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/hassan/32/714_2.png) [@hassan](https://discuss.rubyonrails.org/u/hassan)\
**Post date:** [September 12, 2011, 11:30pm UTC](https://discuss.rubyonrails.org/t/problem-using-mysql-5-1-with-ror-3-1/60820/4 "2011-09-12T23:30:07Z")

</div>

Have you tried generating a new rails app starting out with mysql? e.g. % rails new myapp -d mysql

I just did that as a quick test (on MySQL server 5.1.41) and it worked out of the box.

Rails 3.1.0 / Ruby 1.9.2-p290 (on OS X, though that shouldn't matter)

---

<div class="post-metadata">

**Author:** ![Gero\_Zoltan](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@Gero\_Zoltan](https://discuss.rubyonrails.org/u/Gero_Zoltan)\
**Post date:** [September 18, 2011, 11:37pm UTC](https://discuss.rubyonrails.org/t/problem-using-mysql-5-1-with-ror-3-1/60820/5 "2011-09-18T23:37:01Z")

</div>

Hi, if you're new to Rails on Ubuntu DO NOT follow that blog post, it's simply bad. Use RVM instead: [http://gezope.github.com/rvm\_install\_script/](http://gezope.github.com/rvm_install_script/)

First I highly recommend to start with all default settings. If anything works properly and then you change DB for example and an error occurs - you can be sure that it was the mistake. Postgres is good, since you don't need to change any SQL I think locally everything works fine, and remotely you'll like Postgres later.

HTH Let me know if you've further questions, cheers Zoli
