Error when starting Rails server with MySQL - mysql

I'm running Rails 4.0.3 on Ruby 2.0.0 on Windows 7, and have installed the DevKit (all x64).
I've installed the mysql2 gem using subst X: "C:\Program Files\MySQL\MySQL Server 5.6" and then gem install mysql2 --platform=ruby -- --with-mysql-dir=X:, and it installed fine. I then created a new app with rails new mysql_testy which ran fine, but when I run rails server I get the following error:
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2.rb:8:in 'require': 193: %1 is not a valid Win32 application. - C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2/mysql2.so (LoadError)
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2.rb:8:in '<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in 'block (2 levels) in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in 'each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in 'block in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in 'each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler.rb:131:in 'require'
from C:/Users/Liam/Ruby/mysql_testy/config/application.rb:7:in '<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:74:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:74:in 'block in <top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:71:in 'tap'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:71:in '<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'`
Do you guys have any idea what's happening?

Not sure if you figured it out yet, but I was having the same issue. I installed the 32 bit sql connector, copied the libmysql.dll file from it and pasted it into Ruby/bin folder. Opened a new command prompt and was able to connect to the server.
Before this step though you may have to reinstall a fresh MySQL2 gem pointing to the path of the connector: gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\mysql-connector\mysql-connector-c-6.1.5-win32\lib" --with-mysql-include="C:\mysql-connector\mysql-connector-c-6.1.5-win32\include" --with-mysql-dir="C:\mysql-connector"'
Hope this helps

Related

Can't get WAMP MySQL to work with Ruby on Rails

I am trying to use my WAMP MySQL for a Ruby on Rails installation on my Windows 7 system. I am getting errors (see below) when I try to start the rails WEBrick server.
I've installed the complete Ruby on Rails environment successfully, including the mysql2 gem. When installing the mysql2 gem, I referenced the location of the lib and includes folders of the WAMP mysql and it successfully installed:
C:\wamp\www\simple_cms>gem install mysql2 --no-document -- '--with-mysql-lib="C:\wamp\bin\mysql\mysql5.5.24\lib\" --with-mysql-include="C:\wamp\bin\mysql\mysql5.5.24\include\"
======================================================================================================
\ You've installed the binary version of mysql2.
It was built using MySQL Connector/C version 6.1.5.
It's recommended to use the exact same version to avoid potential issues.
At the time of building this gem, the necessary DLL files were retrieved from:
http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-6.1.5-winx64.zip
\ This gem *includes* vendor/libmysql.dll with redistribution notice in vendor/README.
======================================================================================================
Successfully installed mysql2-0.3.18-x64-mingw32
1 gem installed
I copied the libmysql.dll from "C:\wamp\bin\mysql\mysql5.5.24\lib\libmysql.dll" to "C:\Ruby22-x64\bin\libmysql.dll".
I get the following error when I try to start WEBrick
C:\wamp\www\simple_cms>rails server
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2/mysql2.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/lib/mysql2/mysql2.rb:2:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2.rb:31:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2.rb:31:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:76:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:72:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:72:in `block in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:61:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:61:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler.rb:134:in `require'
from C:/wamp/www/simple_cms/config/application.rb:7:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:78:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in `tap'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in `server'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I have also tried using the libmysql.dll included with the mysql2 gem located at "C:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\mysql2-0.3.18-x64-mingw32\vendor\libmysql.dll" and copying that to "C:\Ruby22-x64\bin\libmysql.dll". That also gave the above errors.
I can access mysql from the command line:
C:\wamp\www\simple_cms>mysql --version
mysql Ver 14.14 Distrib 5.5.24, for Win64 (x86)
I'm not sure what I am doing wrong here. Any help would be appreciated.

"db:migrate rake" throwing eror "cannot load such file -- bundler/setup"

I'm a ruby on rails beginner, and I'm trying to run a rails app on my local mac. I have set up the environment and MySQL database, and it was all smoothie until the last setup step: db:migrate rake. I got the following error:
cannot load such file -- bundler/setup
/Users/snailwalker/vietnam/snailwalker/config/boot.rb:7:in `<top (required)>'
/Users/snailwalker/vietnam/snailwalker/config/application.rb:2:in `<top (required)>'
/Users/snailwalker/vietnam/snailwalker/Rakefile:5:in `<top (required)>'
What am I missing?
cannot load such file -- bundler/setup
Most probably the reason of this issue is that you don't have bundler. You should install bundler then try to run migrations again.
gem install bundler
bundle install
bundle exec rake db:migrate
Hope it'll help you.

Rails + Ubuntu + MySQL = Error

I have XAMPP installed on Ubuntu 12.04 and it all works.
I've also been using Rails for a while with PostgreSQL and it also worked fine.
Today, I tried creating a new app using mysql with mysql2 gem, and got an error while running rake db:create.
I first checked the other Rails/MySQL questions on SO, and will say:
MySQL is running
Using mysql2 gem
DB config looks correct (to me)
database.yml using socket: /opt/lampp/var/mysql/mysql.sock
Error:
/opt/lampp/lib/libmysqlclient.so.18: symbol SSL_accept, version OPENSSL_1.0.1 not defined in file libssl.so.1.0.0 with link time reference - /home/wwc/.rvm/gems/ruby-2.0.0-p353/extensions/x86_64-linux/2.0.0/mysql2-0.3.14/mysql2/mysql2.so
/home/wwc/.rvm/gems/ruby-2.0.0-p353/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `require'
/home/wwc/.rvm/gems/ruby-2.0.0-p353/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `<top (required)>'
/home/wwc/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
/home/wwc/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
/home/wwc/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
/home/wwc/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
/home/wwc/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
/home/wwc/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
/home/wwc/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
/media/fat64/work/_active/josephzidell_rails/config/application.rb:7:in `<top (required)>'
/media/fat64/work/_active/josephzidell_rails/Rakefile:4:in `require'
/media/fat64/work/_active/josephzidell_rails/Rakefile:4:in `<top (required)>'
/home/wwc/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
/home/wwc/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
You can try installing SSL libs using:
apt-get install libssl-dev
You can check the path that it has been installed in using:
apt-file list libssl-dev
you may need to install apt-file first by running:
sudo apt-get install apt-file
apt-file update
The Ruby 2.0.0 got problem with OpenSSL 1.0.1f
Check How can I ensure that Ruby uses an OpenSSL not vulnerable to Heartbleed? and you will realize that your Ruby's OpenSSL lib is not up-to-date
Follow these command (credit: https://coderwall.com/p/tptocq)
rvm pkg install openssl
rvm install 2.0.0 \
--with-openssl-dir=$HOME/.rvm/usr \
--verify-downloads 1
The new installed Ruby 2.0.0 on your machine will got the final OpenSSL version (1.0.1g), which also patched for the Heart Bleed.

Getting errors when starting a rails server with MySQL on mac os

I've been tinkering with this one for several days and I still get the same error. For starters, I have been able to start a newly rails app with sqlite as the database but the application we are working on uses Mysql. So when I go to the app directory and type "rails server" it gives me the following:
/Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql2-0.2.7/lib/mysql2.rb:8:in `require': dlopen(/Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
Referenced from: /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql2-0.2.7/lib/mysql2.rb:8:in `<top (required)>'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `each'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `block in require'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `each'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `require'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/bundler-1.0.15/lib/bundler.rb:120:in `require'
from /Users/gojinjedi/Sites/bluey/config/application.rb:7:in `<top (required)>'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/railties-3.0.7/lib/rails/commands.rb:28:in `require'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/railties-3.0.7/lib/rails/commands.rb:28:in `block in <top (required)>'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/railties-3.0.7/lib/rails/commands.rb:27:in `tap'
from /Users/gojinjedi/.rvm/gems/ruby-1.9.2-p180#rails3/gems/railties-3.0.7/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
So (I think) MySQL development headers aren't installed, which I googled everywhere how to install them and tried most install command line to no success yet. Examples of commands I've tried:
gem install mysql2
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include
I did the bundle install, bundle update and bundle commands in the app directory...I'm running out of options...can you help me?
I'm on mac osx 10.7
have you tried something like this, I'm one Mac OS X (lion) too and I have no problem with the mysql gem. Or may be you can find what you want here
[EDIT]
Or you can simply use ruby-mysql gem for development environment

Problem with MySQL and Rails Server

Final edit: I played with a few different files got some more errors and then reinstalled rvm and everything else from the start, found a few fixes and edited them and finally everything works. thank you everyone for your help
Edit: I have noticed that it says Library not loaded: /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib (LoadError)
But I have mysql 5.5.11, how do I fix that?
I literally have searched for the past 3 hours, but found nothing that worked
Same error occurs when I either try to launch the server or generate a model
I have bundler and mysql2 gems.
builder (2.1.2)
bundler (1.0.12)
erubis (2.6.6)
i18n (0.5.0)
mail (2.2.17)
mime-types (1.16)
mysql2 (0.2.7)
I get the following output:
hrs772:demo kishinmanglani$ rails s
/Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2.rb:8:in `require': dlopen(/Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib (LoadError)
Referenced from: /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2.rb:8:in `<top (required)>'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `require'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `each'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `block in require'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `each'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `require'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler.rb:120:in `require'
from /Users/kishinmanglani/rails_projects/demo/config/application.rb:7:in `<top (required)>'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:28:in `require'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:28:in `block in <top (required)>'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:27:in `tap'
from /Users/kishinmanglani/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Whenever you get load errors you should make sure you have all of the dependencies installed and in place.
Make sure you have gem mysql2 in your Gemfile.
Install bundler if you don't already have it with gem install bundler.
Run bundle (same as bundle install).
Then try running the server again.
mysql2 with rails 3.0.3 is give some error so try to update rails version with 3.0.6
it working fine so try