4

I'm bit confused by "easy" working with ruby on rails, cause I already spend three days by trying create an app.

I work on site5 hosting, and try to create new app. step by step:

$ rails new app -d mysql

$ gem install mysql

$ gem install mysql2

and after

$ rake db:create

it report about error

Could not find gem 'mysql2 (~> 0.2.6, runtime)' in any of the gem sources listed in your Gemfile.

I google it, but still can't fix problem. Can anybody help?

Jordan Running
  • 102,619
  • 17
  • 182
  • 182
alex naumov
  • 331
  • 3
  • 9
  • When you run 'gem list' do you find the mysql gem in the list? – Srisa Jun 23 '11 at 07:10
  • stocktra@stock.travel [~/public_html/ab.awithy.ru/app]# gem list mysql *** REMOTE GEMS *** mysql (2.8.1, 2.7.3) mysql-inspector (0.0.6) mysql-xml (0.1.1) mysql2 (0.3.6, 0.2.6) mysql2_bigint (0.2.6.1) mysql2_model (0.1.2) mysql2mysql (0.0.2) mysql2psql (0.1.0) mysql2xxxx (0.1.1) mysql_backup (0.2.1) – alex naumov Jun 23 '11 at 07:20
  • does that mean, what I have mysql gem? – alex naumov Jun 23 '11 at 07:21

4 Answers4

5

Running rails new app -d mysql will automatically add the required gems to your Gemfile, so you shouldn't need to install them manually with the gem command. Try the following:

$ rails new app -d mysql
$ cd app
$ bundle install
$ rake db:create

I suspect the tutorial you're following is for an older version of Rails. With rails 3, you should be using bundler for all gem management.

Paul Russell
  • 4,727
  • 1
  • 30
  • 28
1

This is how you do it.

gem list --local

Displays list of installed gems. Do you see mysql2 gem? If mysql2 is not installed run

gem install mysql2

You are now ready to launch a new rails app. Go to the desired directory and run

rails new my_app -d mysql

This will create a new rails app in directory my_app with mysql binding. Navigate to the app directory and run

rake about

If every thing is fine you should see the following

Database adapter         mysql2

Fire your favourite text editor and go to config/database.yml Notice there are three databases, one each for development, test, and production. User will be "root" but without password. Enter the root password at all three places. You can also change user.

next open mysql and create three databases

mysql -u root -p
create database my_app_production;
create database my_app_test;
create database my_app_development;
exit

next in the terminal type

rails generate scaffold TableName name:string due:date etc...
rake db:migrate

...and you are done. Hope this helps.

Vikram Sharma
  • 526
  • 5
  • 14
0

Have you tried running gem install mysql2?

If that is not working, try following this tutorial

It looks like your problems are generated by the missing mysql gem.

Here is another question regarding its installation. See if any of the solutions from there apply to you too

Community
  • 1
  • 1
Tudor Constantin
  • 26,330
  • 7
  • 49
  • 72
0

I ran into a similar problem. (I'm using rvm). I think I ran some code like:

The number after libmysqlclient may be different. And the path may be different for you too, but the concept should be similar.

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p136\@rails3tutorial/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle

Cyrus
  • 3,687
  • 5
  • 35
  • 67