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

7
  • Your config/database.yml is probably wrong. Do add it into the question Commented Mar 28, 2017 at 9:29
  • include the commands of how you add that ruby app also Commented Mar 28, 2017 at 9: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'] %> Commented Mar 28, 2017 at 9: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" Commented Mar 28, 2017 at 9:38
  • still i am getting the error.....when i ran above command.....1 gem istalled came.... Commented Mar 28, 2017 at 9:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

10 Comments

i am using Rails 4.2.4 and Ruby 2.1.9
above i have included the code for my database.yml file
gem 'mysql2', '~> 0.3.18' gem 'activerecord-mysql2-adapter', '~> 0.0.3' this all i have added in my gemfile
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.....
will you please let me know what configuration i may specify in my database.yml file for windows....?????????????????
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.