Ruby on Rails : MySQL client library issue when trying to create database - mysql

I have a rails application which is running on Rails 3.2.8 and Ruby 1.9.3.I am also using Mysql server as database.
When I run rake db:migrate, I get the following error:
rake aborted!
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the
client library is 5.5.34.
C:/Rails SampleApps/MyAppName/config/application.rb:7:in `<top (required)>'
C:/Rails SampleApps/MyAppName/Rakefile:5:in `require'
C:/Rails SampleApps/MyAppName/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
How do I solve this issue?
Any help is appreciated..

Since you are using windows, you have two options to solve this :
Either use 2.8.1 version of mysql gem by writing
gem 'mysql', '2.8.1' #in your gemfile
run
bundle install
OR
Simply use mysql2 gem
gem 'mysql2'
and put the libmysql.dll file in installed MySQL bin directory with the one which you can get from the below link in location lib/libmysql.dll from
http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick

gem 'mysql2' ## gemfile
rm Gemfile.lock
bundle install
rake db:drop && rake db:create

Related

LoadError: cannot load such file -- mysql2/mysql2 - on rake db:create

When i run rake db:create, I get this error:
LoadError: cannot load such file -- mysql2/mysql2
/Users/vitorqueiroz/dev/pipeline/config/application.rb:10:in `<top (required)>'
/Users/vitorqueiroz/dev/pipeline/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
I had to mannualy install mysql2 gem because the gemfile specifies the version '0.3.20'
I ran
gem install mysql2 -v '0.3.20' -- --srcdir=/usr/local/include/mysql
Bundle install runs fine, and says everything is installed.
bundle list mysql2 evaluates to:
/Users/vitorqueiroz/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/mysql2-0.3.20
--
Any alternatives?
You can try
bundle exec rake db:create
to be sure that bundled gems are loaded.
https://bundler.io/man/bundle-exec.1.html

error setting up MySQL database for RoR

I'm new to Ruby on Rails and am having trouble setting up my first MySQL database.
I followed the instructions on here: https://gorails.com/setup/osx/10.12-sierra
And I reached the very end where it asks you to run "rake db:create". When I execute this in the terminal, I get the following error:
MacBook-Air-de-myusername% rake db:create
rake aborted!
cannot load such file -- bundler/setup
/Users/myusername/splash/config/boot.rb:3:in `<top (required)>'
/Users/myusername/splash/config/application.rb:1:in `require_relative'
/Users/myusername/splash/config/application.rb:1:in `<top (required)>'
/Users/myusername/splash/Rakefile:4:in `require_relative'
/Users/myusername/splash/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
Can anyone advise on what is happening? I know that I have "cd"-ed into the correct directory, so that can't be it.
Install bundler gem and run bundle install:
$ gem install bundler
$ bundle install
Now run rake again:
$ rake db:create
If that doesn't work, then run the complete command:
$ bundle exec rake db:create
To understand more about bundle command, check this question.
Run:
gem install bundler
bundle install
bundle exec rake db:create
I think you are in incorrect folder.
try cd splash
then run following command:
bundle install
bundle exec rake db:create

Can't create rails application with mysql

I run
rails new mothersapp -d mysql
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/javascripts/application.js
create ----- Some stuff here ------
create ----- Some stuff here ------
create ----- Some stuff here ------
create vendor/assets/javascripts/.keep
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.keep
run bundle install
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using .... some stuff here ...
Using .... some stuff here ...
Using .... some stuff here ...
Using coffee-rails 4.1.0
Using multi_json 1.11.0
Using jbuilder 2.2.13
Using jquery-rails 4.0.3
Errno::EACCES: Permission denied # rb_sysopen - /home/ayush/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18/README.md
An error occurred while installing mysql2 (0.3.18), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.18'` succeeds before bundling.
run bundle exec spring binstub --all
/home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/resolver.rb:369:in `resolve': Could not find gem 'mysql2 (>= 0) ruby' in the gems available on this machine. (Bundler::GemNotFound)
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/resolver.rb:167:in `start'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/resolver.rb:129:in `resolve'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/definition.rb:193:in `resolve'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/definition.rb:132:in `specs'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/definition.rb:177:in `specs_for'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/definition.rb:166:in `requested_specs'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/environment.rb:18:in `requested_specs'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/runtime.rb:13:in `setup'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler.rb:122:in `setup'
from /home/ayush/.rvm/gems/ruby-2.2.1#global/gems/bundler-1.8.4/lib/bundler/setup.rb:18:in `<top (required)>'
from /home/ayush/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ayush/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
How do I fix the error which I get at last? I am on ubuntu 14.04.
Creating a new rails application without mysql works fine. But, when I put mysql with a -d flag. I am getting this error. Can someone please explain what's the problem?
On running gem install mysql2 -v '0.3.18' it gave :
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted # chmod_internal - /home/ayush/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18/README.md

mysql doesn't seem to work with my new rails app

I can't seem to get mysql to work with my new rails app at all... terminal copy below:
Janes-MacBook-Pro:development janelee$ cd hellomysql
Janes-MacBook-Pro:hellomysql janelee$ rails server
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): no suitable image found. Did find: (LoadError)
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2.rb:9
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `each'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `each'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler.rb:122:in `require'
from /Users/janelee/Development/hellomysql/config/application.rb:7
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:53:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:53
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:50
from script/rails:6:in `require'
from script/rails:6
Janes-MacBook-Pro:hellomysql janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): no suitable image found. Did find:
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
(See full trace by running task with --trace)
and I tried this too:
Janes-MacBook-Pro:hello janelee$ gem uninstall sqlite3
You have requested to uninstall the gem:
sqlite3-1.3.5
i18n-0.6.0 depends on [sqlite3 (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn] y
Successfully uninstalled sqlite3-1.3.5
Janes-MacBook-Pro:hello janelee$ ARCHFLAGS="-arch x86_32" sudo gem install sqlite3
Password:
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.5
1 gem installed
Janes-MacBook-Pro:hello janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle, 9): no suitable image found. Did find:
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle
(See full trace by running task with --trace)
and this:
Janes-MacBook-Pro:hello janelee$ gem uninstall sqlite3
You have requested to uninstall the gem:
sqlite3-1.3.5
i18n-0.6.0 depends on [sqlite3 (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn] y
Successfully uninstalled sqlite3-1.3.5
Janes-MacBook-Pro:hello janelee$ ARCHFLAGS="-arch x86_64" sudo gem install sqlite3
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.5
1 gem installed
Janes-MacBook-Pro:hello janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle, 9): no suitable image found. Did find:
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle
(See full trace by running task with --trace)
What else should I try before reinstall Lion?
Look into using Ruby Version Manager (called rvm) and then update Ruby. Try using ver 1.9 of ruby or higher. Don't reinstall your OS. If anything, remove rails, remove ruby. Install rvm, install ruby 1.9, install rails. If you follow that recipe, all should be well.
Configuring Rails to work with MySQL will happen through changing the file:
myappname/config/database.yml
Good information is here: How do I set MySQL as the default database in Rails 3?
... and here: Create a new Ruby on Rails application using MySQL instead of SQLite
Get used to looking at the Rails guides. Examples like this: http://guides.rubyonrails.org/getting_started.html#configuring-a-database are all you need to get going.

version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1

Hi i am using rails version 3.0.7 when i run rails generate model task name:string i m getting following warning
WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/railtie.rb:59
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/base.rb:1904
from /home/sun/railsapp/dog/vendor/plugins/attribute_fu/init.rb:1
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/plugin.rb:81
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `send'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
from /home/sun/railsapp/dog/config/environment.rb:5
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require_environment!'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:16
from script/rails:6:in `require'
from script/rails:6
when i try to install activerecord-mysql2-adapter by :gem install activerecord-mysql2-adapter
ERROR: Could not find a valid gem 'activerecord-mysql2-adapter' (>= 0) in any repository
please help me
thanks
The problem is because you are trying to install the latest version of mysql2 which is incompatible with rails 3.0.x version
SO, in your Gemfile change the line for mysql2 gem for this:
gem 'mysql2', '< 0.3'
then bundle command
and then when the new mysql2 gem file ( i think is 0.2.7 ) you will solve the problem.
if still not working try this too:
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Users/YOUR_USER_NAME/.rvm/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
gem 'mysql2', '< 0.3' is the only way on Rails 3.0.7 (before 3.1)
UPDATE: sorry, that was not the case also, did't work either, there is a better way:
vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.2/lib/active_record/connection_adapters$[rails307]$ ls
em_mysql2_adapter.rb mysql2_adapter.rb
take mysql2_adapter.rb file from mysql2 gem version 0.2.x and copy it to the above location
now it works for me with just gem 'mysql2' in Gemfile
After trying the solution offered by #eveevans I was still having version issues. Then reading the suggestion by #rubyconvict, I thought instead about using the -v option for gem rather than pushing files about.
Here's what I found eventually resolved my struggle with the dreaded "version of mysql2 (0.3.2)" message on DreamHost:
# in mysql, create example_app & example_app_test ...
# ... for the purposes of this example only, production == development db
rails new example_app --database=mysql --freeze
cd example_app
vim config/database.yml
# change settings for host, user, password ...
# ... database for test (example_app_test) ...
# ... & database for production & development (example_app)
vim Gemfile
# gem 'mysql2', '< 0.3'
gem uninstall mysql2 # if installed: gem list -d mysql2
gem install mysql2 -v 0.2.7
rake db:migrate
From there, I can move onto other RoR fun, like perhaps modifying routes (vim config/routes.rb ... however your mileage may vary).
WARNING: Please use the 0.2.x
releases if you plan on using it in
Rails <= 3.0.x
so in short just use the latest in the 0.2.x branch for the mysql2 gem.