Question

I am trying to develop ruby on rails aplication using mysql database in Ubuntu environment. I have installed rails and mysql succesfully. But when I try to generate model, it reports the message

 rails g model person
      invoke  active_record
/home/meuser/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.1.4/lib/bundler/rubygems_integration.rb:147:in `block in replace_gem': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) (LoadError)

Then I tried to install activerecord-mysql-adapter:

meuser@ubuntu:~/myproject$ gem install activerecord-mysql-adapter
ERROR:  Could not find a valid gem 'activerecord-mysql-adapter' (>= 0) in any repository
ERROR:  Possible alternatives: activerecord-jdbcmysql-adapter, activerecord-jdbcmssql-adapter, activerecord-fb-adapter, activerecord-odbc-adapter, activerecord-jdbc-adapter
meuser@ubuntu:~/myproject$ 

Initiated by the answers below, I also tried this:

meuser@ubuntu:~/myproject$ gem "mysql2", "< 0.3"
ERROR:  While executing gem ... (RuntimeError)
    Unknown command mysql2,
meuser@ubuntu:~/myproject$ 

And this:

meuser@ubuntu:~/myproject$ gem 'mysql2'
ERROR:  While executing gem ... (RuntimeError)
    Unknown command mysql2
meuser@ubuntu:~/myproject$ 

And this:

meuser@ubuntu:~/myproject$  gem install "mysql2" -v=2.8.17
ERROR:  Could not find a valid gem 'mysql2' (= 2.8.17) in any repository
ERROR:  Possible alternatives: mysql2
meuser@ubuntu:~/myproject$ 

And this:

meuser@ubuntu:~/myproject$ sudo apt-get install libmysql-ruby libmysqlclient-dev
[sudo] password for meuser: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libmysqlclient-dev is already the newest version.
libmysql-ruby is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
meuser@ubuntu:~/myproject$ gem "mysql2", "< 0.3"
ERROR:  While executing gem ... (RuntimeError)
    Unknown command mysql2,
meuser@ubuntu:~/myproject$ 

Here is my database.yml file

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  pool: 5
  database: myproject_db
  username: root
  password: somepassword
  host: localhost
  socket: /var/run/mysqld/mysqld.sock

Does anyone knows solution for this issue? Thanks.

Was it helpful?

Solution

The adapter gem is called 'mysql2', and you need add it to your gemfile:

gem 'mysql2'

Then run the bundle command and edit your database.yml file to point to the right database:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: yourapp_development
  pool: 5
  username: root
  password:
  socket: /var/run/mysqld/mysqld.sock

OTHER TIPS

try to install mysql2 gem in version < 0.3 like 0.2.8 it is common issue.

in Gemfile type

gem "mysql2", "< 0.3"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top