Rails on Mac - rake db:create error - mysql

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

Related

MySQL gem is not installing on M1 mac

I am facing issue while installing MySQL gem on M1 mac. Bundle install fas failing to build mysql gem
An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
In Gemfile:
mysql2
Found a solution which suggested to install mysql2 gem using following command
$ arch -x86_64 gem install mysql2 -v 0.5.3 -- --srcdir=/usr/local/mysql/include
This actually solved bundle install issue, but when i tried rails c got this error.
$ rails c
/Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:332:in `block in require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:299:in `load_dependency'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:332:in `require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/mysql2-0.5.3/lib/mysql2.rb:36:in `<main>'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bundler-2.3.8/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bundler-2.3.8/lib/bundler/runtime.rb:55:in `each'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bundler-2.3.8/lib/bundler/runtime.rb:55:in `block in require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bundler-2.3.8/lib/bundler/runtime.rb:44:in `each'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bundler-2.3.8/lib/bundler/runtime.rb:44:in `require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/bundler-2.3.8/lib/bundler.rb:176:in `require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/spring-2.1.1/lib/spring/application.rb:92:in `require'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/spring-2.1.1/lib/spring/application.rb:92:in `preload'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
from /Users/maneeshb/.rvm/gems/ruby-2.6.9/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
from /Users/maneeshb/.rvm/rubies/ruby-2.6.9/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/maneeshb/.rvm/rubies/ruby-2.6.9/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
Please help me to solve this issue.
This solved the issue
brew install openssl zstd mysql
LIBRARY_PATH=$(brew --prefix zstd)/lib/:$(brew --prefix openssl)/lib/ gem install mysql2

mysql2 GemRequireError during server start

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.

Incorrect MySQL client library version! This gem was compiled for 5.5.37 but the client library is 5.6.25 [duplicate]

This question already has answers here:
mysql2 gem compiled for wrong mysql client library
(8 answers)
Closed 6 years ago.
I upgraded my Ubuntu from 2014.04 to 2015.04 and now bundle exec rake db:migrate returns an error:
$ bundle exec rake db:migrate --trace
rake aborted!
Incorrect MySQL client library version! This gem was compiled for 5.5.37 but the client library is 5.6.25.
/home/nico/.rvm/gems/ruby-1.9.3-p362/gems/mysql2-0.2.11/lib/mysql2.rb:9:in `require'
/home/nico/.rvm/gems/ruby-1.9.3-p362/gems/mysql2-0.2.11/lib/mysql2.rb:9:in `<top (required)>'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
/home/nico/myapp/config/application.rb:7:in `<top (required)>'
/home/nico/myapp/Rakefile:4:in `require'
/home/nico/myapp/Rakefile:4:in `<top (required)>'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load_rakefile'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:583:in `raw_load_rakefile'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:89:in `block in load_rakefile'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:88:in `load_rakefile'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:72:in `block in run'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/bin/rake:19:in `load'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/bin/rake:19:in `<main>'
/home/nico/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `eval'
/home/nico/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `<main>'
How to solve this problem?
I would rather avoid changing server-side versions.
The answers at I can't run "bundle update" because of "mysql2" gem do not solve the problem.
Local versions:
gem 2.4.8
Rails 3.0.19
mysql Ver 14.14 Distrib 5.6.25
Running these commands solved the problem:
gem uninstall mysql2
bundle install
I ran into the same problem and the accepted answer didn't work for me, most likely because I used capistrano, which installs all gems into a per-app shared directory.
bundle show mysql2
(run in your app's folder) will show you where mysql is installed. Then delete that as well as the the specification.
rm -rf /path/to/application/shared/bundle/ruby/<version>/gems/mysql2-<version>
rm /path/to/application/shared/bundle/ruby/<version>/specifications/mysql2-<version>.gemspec
should do the trick. Alternatively just delete the complete bundle/* and reinstall everything.

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