mysql2 GemRequireError during server start - mysql

I'm trying to get an old Ruby on Rails project up and running. The project uses Ruby 1.9.3p484 and a bunch of gems, including mysql2, that are all successfully installed when I run bundle install. However, when I run a script/rails server (like I said, old version of RoR), I get the following mysql2 error:
/Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/bundler-1.11.2/lib/bundler/runtime.rb:81:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'mysql2'. (Bundler::GemRequireError)
and the stack trace:
/Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/bundler-1.11.2/lib/bundler/runtime.rb:81:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'mysql2'. (Bundler::GemRequireError)
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /Users/ryan/vagrant/source/adage/web/htdocs/iwny/config/application.rb:8:in `<top (required)>'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/railties-3.0.20/lib/rails/commands.rb:28:in `require'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/railties-3.0.20/lib/rails/commands.rb:28:in `block in <top (required)>'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/railties-3.0.20/lib/rails/commands.rb:27:in `tap'
from /Users/ryan/.rvm/gems/ruby-1.9.3-p484#iwny/gems/railties-3.0.20/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Like I said, bundle install worked just fine. The Gemfile contains
gem 'mysql2', '< 0.3'
and versions for various software include the following:
ruby 1.9.3p484
rails 3.0.20
rake 10.0.3
rspec 2.12.2
rake-compiler 10.5.0
mysql: Server version: 5.5.44-37.3-log Source distribution
I can't really mess with too much core stuff as this is an established site/repo so I have to work with what I have here.

Related

Ruby on Rails - Couln't find mysql2.so

I have been working on Ruby on Rails since 2 months go and now I want to change the database system so I installed the gem mysql2 by this command:
gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\mysql-connector\lib" --with-mysql-include="C:\mysql-connector\include" --with-mysql-dir="C:\mysql-connector"'
And It works!
but the problem is when I want to run rails server again I got this error
c:\zreactor\demo>rails server
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `requir
e': 126: The specified module could not be found. - C:/Ruby200-x64/lib/ruby/ge
ms/2.0.0/extensions/x64-mingw32/2.0.0/mysql2-0.3.16/mysql2/mysql2.so (LoadError)
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2.rb
:8:in `<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.3/lib/bundler/r
untime.rb:76:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.3/lib/bundler/r
untime.rb:76:in `block (2 levels) in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.3/lib/bundler/r
untime.rb:72:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.3/lib/bundler/r
untime.rb:72:in `block in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.3/lib/bundler/r
untime.rb:61:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.3/lib/bundler/r
untime.rb:61:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.3/lib/bundler.r
b:133:in `require'
from c:/zreactor/demo/config/application.rb:7:in `<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/co
mmands.rb:74:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/co
mmands.rb:74:in `block in <top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/co
mmands.rb:71:in `tap'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/co
mmands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I searched in the source and it looks everything ok,I have no idea why I got this error.
I'm working on W8 with ruby 2.0 and rails 4.0.2.
I would appreciate your help guys,
Thanks!
Most likely you need to regenerate libmysql.lib as described here:
...mysql2/mysql2.so: [BUG] Segmentation fault ruby 2.0.0p247

Rails on Mac - rake db:create error

I installed RVM and rails on my MAC (Mavericks 10.9.1) and I try to run rake db:create. However I constantly get this error:
MacBook-Pro-Szymon:wybierzto Fengson$ rake db:create
rake aborted!
dlopen(/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/extensions/x86_64-darwin-12/2.0.0-static/mysql2-0.3.14/mysql2/mysql2.bundle, 9): Library not loaded: /opt/local/lib/mysql5/mysql/libmysqlclient_r.16.dylib
Referenced from: /Users/Fengson/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/extensions/x86_64-darwin-12/2.0.0-static/mysql2-0.3.14/mysql2/mysql2.bundle
Reason: image not found - /Users/Fengson/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/extensions/x86_64-darwin-12/2.0.0-static/mysql2-0.3.14/mysql2/mysql2.bundle
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `require'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `<top (required)>'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:76:in `require'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:72:in `each'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:72:in `block in require'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:61:in `each'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:61:in `require'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.5.1/lib/bundler.rb:131:in `require'
/Users/Fengson/UJ/ProjektZespolowy/wybierzto/config/application.rb:12:in `<top (required)>'
/Users/Fengson/UJ/ProjektZespolowy/wybierzto/Rakefile:4:in `require'
/Users/Fengson/UJ/ProjektZespolowy/wybierzto/Rakefile:4:in `<top (required)>'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `eval'
/Users/Fengson/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
Also, how can I properly install MySQL Server so that I can set a default password? It asked me for a password on Windows machine but here it didn't when I was installing MySQL5 + server. Thanks!
try reinstall mysql through homebrew. and reinstall mysql gem
gem install mysql -- --with-mysql-config path/to/mysql_config

Connect existing MySQL database in rails

I want to connect my Ruby on Rails application with a MySQL database, which was developed separately. For this connection I used the
development environment:
adapter: mysql
username: root
password: ******
host: 127.0.0.1
port: 3306
When I try to make the MySQL connection in Rails it shows:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mysql.rb:4:in `require': Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.5.9. (RuntimeError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mysql.rb:4:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
from D:/registration/config/application.rb:7:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:53:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:53:in `block in <top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
D:\registration>
Also, when I try my rake command it shows:
rake aborted!
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.5.9.
D:/registration/config/application.rb:7:in `<top (required)>'
D:/registration/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
D:\registration>
How can I connect to my database?
As per the error it seems like you are using a newer version of the gem than your MySQL client.
It says:
Your gem has been compiled (created with) my sql client version 6.0.0.
Your actual my sql client version (in your machine) is 5.5.9.
Could you post your MySQL gem version as well as your MySQL client version?
Upgrating your MySQL client to version 6.0.0 should fix this issue.

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