1

I tried installing ruby on windows 7 and using mysql2

downloaded the latest installer here for windows 7 64 bit downloaded the Devkit and followed this steps found here for devkit installation

did this gem install rails

downloaded mysql from here following the instruction found here

now after everything is installed i created my app using this line

rails new test_app -d mysql

after changing my directory to my new app

i ran this line rails s

and i got this error

C:\Ruby22-x64\my_test_app>rails s
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2/mysq
l2.rb:2:in `require': cannot load such file -- mysql2/2.2/mysql2 (LoadError)
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/li
b/mysql2/mysql2.rb:2:in `<top (required)>'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/li
b/mysql2.rb:31:in `require'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/li
b/mysql2.rb:31:in `<top (required)>'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.9.4/lib/bundler/ru
ntime.rb:76:in `require'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.9.4/lib/bundler/ru
ntime.rb:76:in `block (2 levels) in require'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.9.4/lib/bundler/ru
ntime.rb:72:in `each'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.9.4/lib/bundler/ru
ntime.rb:72:in `block in require'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.9.4/lib/bundler/ru
ntime.rb:61:in `each'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.9.4/lib/bundler/ru
ntime.rb:61:in `require'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.9.4/lib/bundler.rb
:134:in `require'
        from C:/Ruby22-x64/my_test_app/config/application.rb:7:in `<top (require
d)>'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/com
mands/commands_tasks.rb:78:in `require'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/com
mands/commands_tasks.rb:78:in `block in server'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/com
mands/commands_tasks.rb:75:in `tap'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/com
mands/commands_tasks.rb:75:in `server'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/com
mands/commands_tasks.rb:39:in `run_command!'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/com
mands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

what is it that I am missing here? mysql2 is inside my Gemfile.

Though I have not connected my rails to my database or configured the database.yml since I cannot find any instructions on how to do that.

Community
  • 1
  • 1
magicianiam
  • 1,474
  • 7
  • 33
  • 70

2 Answers2

3

Basically following the instructions in here I just completed an installation from zero to fully functional on Windows 7 64bit.

In your case the problem may lie in the version of the gem mysql2 or in the manner in which it was installed; you could start with uninstall and re-install the 0.2.6 version @see Gediminas answer and check the GemFile if you have a different version. This save me from troubles with specific:

--with-mysql-dir=.... --with-mysql-lib=.... --with-mysql-include=....


Anyway I will detail each steps of my checklist so you can see if there are differences to your installation

Notice: according to http://rubyinstaller.org/downloads/ I select the 2.1.* ( not the last one) and I downloaded the standard 32-bit version because the 64-bit versions of Ruby are relatively new on the Windows area and not all the packages have been updated to be compatible with it. To use this version you will require some knowledge about compilers and solving dependency issues, which might be too complicated if you just want to play with the language. Also reading on the same page : Ruby 2.0.0 and above -->: mingw64-32-4.7.2

cd C:\DevKit 
ruby dk.rb init 
ruby dk.rb install 
devkitvars.bat 
  • Don't forget to copy libmysql.dll in my case, after installing mysql community 5.6 i found three different dll ( in dimension) with the same name:
cd \
find . -name "libmysql.dll"
./Program Files/MySQL/MySQL Connector.C 6.1/lib/libmysql.dll
./Program Files/MySQL/MySQL Server 5.6/lib/libmysql.dll
./Program Files/MySQL/MySQL Workbench 6.2 CE/libmysql.dll``

Definitively i choose this option:

C:>cd C:\Ruby21\bin>
C:\Ruby21\bin> copy "\Program Files\MySQL\MySQL Server 5.6\lib\libmysql.dll" .
        1 file(s) copied.
C:\Ruby21\bin>gem update --system
...
[snip]
...
C:\Ruby21\bin>gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.6
  - RUBY VERSION: 2.1.6 (2015-04-13 patchlevel 336) [i386-mingw32]
  - INSTALLATION DIRECTORY: C:/Ruby21/lib/ruby/gems/2.1.0
  - RUBY EXECUTABLE: C:/Ruby21/bin/ruby.exe
  - EXECUTABLE DIRECTORY: C:/Ruby21/bin
  - SPEC CACHE DIRECTORY: C:/Users/rondadev/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-mingw32
  - GEM PATHS:
     - C:/Ruby21/lib/ruby/gems/2.1.0
     - C:/Users/rondadev/.gem/ruby/2.1.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - C:\DevKit\bin
     - C:\DevKit\mingw\bin
     - C:\Ruby21\bin
     - C:\Windows\system32
     - C:\Windows
     - C:\Windows\System32\Wbem
     - C:\Windows\System32\WindowsPowerShell\v1.0\
     - C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\
     - C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
     - C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
     - C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.4

ready to install rails and create the first application:

gem install rails

gem install mysql2 -v 0.2.6

rails new test_app -d mysql

At the end the last steps:

  1. connected MySQL Workbench and created a new schema named test_app_development (to create a new schema you can press the 4th icon in the tool bar with a cylinder and a plus sign ..see next screenshot)

  2. fixed username and password in config/database.yml as in sansarp anwser enter image description here

  3. Migrated the database

MySQL Workbench and database migration after migrate your schema should look like this: enter image description here

  1. executed rails -s

  2. successfully opened in the browser http://localhost:3000

```

C:\Projects\test_app>rake db:migrate --trace
DL is deprecated, please use Fiddle
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:dump

C:\Projects\test_app>rails s
DL is deprecated, please use Fiddle
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-04-29 00:20:21] INFO  WEBrick 1.3.1
[2015-04-29 00:20:21] INFO  ruby 2.1.6 (2015-04-13) [i386-mingw32]
[2015-04-29 00:20:21] INFO  WEBrick::HTTPServer#start: pid=4144 port=3000


Started GET "/" for ::1 at 2015-04-29 00:20:34 +0200
Processing by Rails::WelcomeController#index as HTML
  Rendered C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/templates
/rails/welcome/index.html.erb (0.0ms)
Completed 200 OK in 31ms (Views: 15.6ms | ActiveRecord: 0.0ms)
Community
  • 1
  • 1
Franco Rondini
  • 10,841
  • 8
  • 51
  • 77
  • do i need to install connector/python 3.4? during the check requirements part of the mysql installation it states manual and i am not sure if i should install it? – magicianiam Apr 29 '15 at 11:39
  • @magicianlam : answer update: added screenshot with details about options of mySQL installation; all what I installed is listed in the answer, if particular check is required on my filesystem leave me a comment. – Franco Rondini Apr 29 '15 at 13:27
  • I just installed everything required for mysql, hope it works and also i followed those found in your screenshot, though can you provide further instructions for the last step, primarily steps 1 to 3. thank you – magicianiam Apr 29 '15 at 13:30
  • i was not able to install the workbench, should I install the 64bit or the 32bit version? – magicianiam Apr 29 '15 at 14:03
  • see the answer for the name of the msi file, I download it from here: http://dev.mysql.com/downloads/file.php?id=456518 - [Windows (x86, 32-bit), MSI Installer 5.6.24 286.7M] and I see the "C:\Program Files\MySQL\MySQL Workbench 6.2 CE\MySQLWorkbech.exe" as a 64bit process on task manager. – Franco Rondini Apr 29 '15 at 14:31
  • It's working! Can you give me some links where I can learn to start programming in rails? the basic hello world would do. thanks again :) a lot of steps for working on a language. hope they can make a 1 time installer like xampp. – magicianiam Apr 29 '15 at 14:46
0

In config/database.yml have the following setting for your development environment as:

development:
  adapter: mysql2 
  database: db_name 
  username: your_username
  password: your_password
sansarp
  • 1,446
  • 11
  • 18