1

I am working on a Project where i switched my database from sqlite3 to mysql.All configurations is done properly,but i am getting error while i am running rake db:migrate on Windows machine.

PS D:\workspace\hrms> rake db:migrate
rake aborted!
LoadError: Could not load 'active_record/connection_adapters/mysql2_adapter'. Make sure that the adapter in config/datab
ase.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapte
r gem to the Gemfile.
D:/workspace/hrms/config/environment.rb:5:in `<top (required)>'
LoadError: cannot load such file -- mysql2
D:/workspace/hrms/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

this is my database.yml file for windows

default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: **** socket: /var/run/mysqld/mysqld.sock development: <<: *default database: hrms_development test: <<: *default database: hrms_test production: <<: *default database: hrms_production username: hrms password: <%= ENV['HRMS_DATABASE_PASSWORD'] %>

is it correct...or i need to include some more settings??????????????

* extconf.rb failed * Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=D:/Ruby21-x64/bin/ruby --with-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

D:/Ruby21-x64/lib/ruby/gems/2.1.0/extensions/x64-mingw32/2.1.0/mysql2-0.4.5/mkmf.log

extconf failed, exit code 1

Mahesh Sharma
  • 221
  • 1
  • 13
  • Your `config/database.yml` is probably wrong. Do add it into the question – Ho Man Mar 28 '17 at 09:29
  • include the commands of how you add that ruby app also – Beginner Mar 28 '17 at 09:29
  • default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: ***** socket: /var/run/mysqld/mysqld.sock development: <<: *default database: hrms_development test: <<: *default database: hrms_test production: <<: *default database: hrms_production username: hrms password: <%= ENV['HRMS_DATABASE_PASSWORD'] %> – Mahesh Sharma Mar 28 '17 at 09:37
  • i have included mysql using.....bundle config build.mysql2 '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include" – Mahesh Sharma Mar 28 '17 at 09:38
  • still i am getting the error.....when i ran above command.....1 gem istalled came.... – Mahesh Sharma Mar 28 '17 at 09:39
  • but still i am getting error while running rake db:migrate – Mahesh Sharma Mar 28 '17 at 09:40
  • now i am getting this error........Exiting D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/mysql2-0.3.21-x64-mingw32/lib/mysql2/client.rb:70:in `connect': Unknown database 'hrms_development' (Mysql2::Error) – Mahesh Sharma Mar 28 '17 at 10:41

1 Answers1

0

There can be two reasons;

  1. You did not specify the adapter properly in database.yml
  2. You missed to add necessary gem to gem file.

Please share your rails version and can you try with 'mysql' as adapter.

Rajeev G
  • 16
  • 4
  • i am using Rails 4.2.4 and Ruby 2.1.9 – Mahesh Sharma Mar 28 '17 at 09:42
  • above i have included the code for my database.yml file – Mahesh Sharma Mar 28 '17 at 09:43
  • gem 'mysql2', '~> 0.3.18' gem 'activerecord-mysql2-adapter', '~> 0.0.3' this all i have added in my gemfile – Mahesh Sharma Mar 28 '17 at 09:44
  • after that ran.........bundle config build.mysql2 '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include" ..........and was successfull.....1 gem installed came..... – Mahesh Sharma Mar 28 '17 at 09:45
  • will you please let me know what configuration i may specify in my database.yml file for windows....????????????????? – Mahesh Sharma Mar 28 '17 at 09:47
  • In Windows I too faced some challenges with gems and got corrected after downgrading the gem versions. That is why I suggested *mysql* as adapter instead of *mysql2* – Rajeev G Mar 28 '17 at 09:51
  • Gem::LoadError: Specified 'mysql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your Gemfile (an d ensure its version is at the minimum required by ActiveRecord). this error came....when i removed 2 from mysql2... – Mahesh Sharma Mar 28 '17 at 09:54
  • Please do a try. Also, please check whether the link below provide any help; http://stackoverflow.com/questions/19014117/ruby-mysql2-gem-installation-on-windows-7 – Rajeev G Mar 28 '17 at 09:54
  • Please add gem 'mysql' to your gem-file and do bundle install then. – Rajeev G Mar 28 '17 at 09:55
  • i am getting this error...whenever running gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/MySQL/MySQL Connector C 6.1/"' – Mahesh Sharma Mar 28 '17 at 10:16