Rails: bundle doesn't show installed mysql2 gem - mysql

I know may be this is a popular problem but i try many solutions and not get to finish
I try to install mysql in rails with
gem install mysql2
And I get the result
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.18
1 gem installed
But when i try to execute the command
bundle show mysql2
I get
Could not find gem 'mysql2'.
All these command execute in my application root directory
What is the problem ?

bundle show lists the names and versions of all gems that are required by your Gemfile, so at first you should add mysql2 gem to it:
gem 'mysql2'

Related

How can I solve this Mysql2 gem error in CentOS 8?

I need to setup ruby on rails with MySQL
I already have installed MYSQL
when I do Bundle install it shows following error.
Fetching mysql2 0.3.21
Installing mysql2 0.3.21 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
I am using Cent-os 8
anyone can help
Thanks
Run first this command gem 'mysql2', '~> 0.3.21' in terminal and when finish then try bundle again

Ruby can not require mysql

On Mac OS X 10.9.2, I use this command line on terminal to install mysql lib for Ruby:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install mysql2
And it shows:
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.15
Parsing documentation for mysql2-0.3.15
Done installing documentation for mysql2 after 0 seconds
1 gem installed
But I still can not use:
require 'rubygems'
require 'mysql'
It shows :
in `require': cannot load such file -- mysql (LoadError)
What should I do next?
You have installed the 'mysql2' gem. You need to require that gem within your code:
require 'mysql2'
Then everything should work just fine.

Can't Connect to MySql From Rails Application in Windows

I am trying to create a Rails application in windows with MySQL as the Database. I have created a rails app and it runs just as fine. But when I try to connect to the mySQL database I am getting weird errors, which I was unable to solve after hours of Googling and hunting around. Maybe I am performing a silly mistake, new to Rails and Ruby.
Here is how I proceeded in creating the app with MYSQL
In command prompt
rails new sample_app -d mysql
[success]
Opened a new command prompt window and
C:\sites\cd sample_app> rails -s
Now I get this error
Could not find gem mysq12 (>=0) in any of the gem sources listed in your Gemfile
Run bundle install to install missing gems
Note: I didn't get the error when I created my first rails app without using Mysql.
Next, I ran this command
gem install mysql2
And got this
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby1.8.7/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
checking for rb_hash_dup()... no
checking for rb_intern3()... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Next I ran this one -
bundle install
Closed all command prompt windows, opened a new one, moved to my app directory and typed
rails -s
Error:
could not find gem mysq12 (>=0) in any of the gem sources listed in your Gemfile
Run bundle install to install missing gems
Here are some information which I think will be useful
- Rails 3.0.9
- Ruby 1.8.7
- rake (10.1.0, 0.8.7)
- mysql (2.9.1 x86-mingw32)
- MySql 5.6 installed and running (I have created a DB and tables)
- OS: Windows 7 64bit
Here is how my database.yaml file looks like:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: sample_app_development
pool: 5
username: root
password: buiskol
host: localhost
Here is how the gemfile of the app looks like
source 'http://rubygems.org'
gem 'rails', '3.0.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2', '~> 2.9.1'
I think the problem is that my mysql2 gem is not properly installed. I am not sure where I am doing the mistake. Any help will be much appreciated.
Why are you using gem 'mysql2', '~> 2.9.1' instead of gem "mysql2", "~> 0.3.13"? According to this, there isn't any 2.9.1 version, maybe you meant 0.2.9 ? Otherwise, you're installing the wrong version of that gem, or the wrong gem with the right version.
You should use:
gem "mysql", "~> 2.9.1"
or
gem "mysql2", "~> 0.3.13"
in your gem file. Since there's no version 2.9.1 for mysql2, correct the typo and try again

How to resolve Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.)

I am running a rails3 app on Dreamhost: not the best call but I need it operational before I can pitch migrating to Heroku.
I am using rails 3.2.1, and ruby 1.8.7 with
gem 'mysql2', '~> 0.2.7'
in my Gemfile...
I get the following error when I deploy and reload:
Please install the mysql adapter: gem install activerecord-mysql-adapter (mysql is not part of the bundle. Add it to Gemfile.)
I have tried gem 'mysql2', gem 'mysql2', '< 0.3' and get the exact same issue.
Any other ideas?
First try adding config.assets.initialize_on_precompile = false to your application.rb.
Then make sure your DATABASE_URL var starts with mysql2:// instead of mysql://
In general when rails is trying to be helpful it will try to generate the name of an adapter gem based on whatever you have in your database.yml. If that gem doesn't exist it's a good indication that something with the adapter line is wrong
for mysql2 the adapter type needs to be mysql2 as well
database.yml
adapter: mysql2
I had the same problem and after checking if you have in database.yml that you have adapter:mysql2 you should check if you have the gem of mysql loaded.
in your Gemfile you should have the line : gem "mysql2" and not other database like sqlite3 which was my case.
Hope this helps.
I get into the same situation of trying to set up mysql with Ruby on Rails for my
Windows Vista platform installed with MySQL 5.5 and Rails Installer for Ruby 1.93.
After getting the adapter and connector for mysql2, I still get this error message : "rubygems_integration.rb:143:in block in replace_gem': Please install the mysql2
adapter:gem install activerecord-mysql2-adapter` (mysql2 is not part of the b
undle. Add it to Gemfile.) (LoadError)"
I checked the my gem directory "Ruby1.9.3\lib\ruby\gems\1.9.1\gems" and see
both activerecord-mysql2-adapter-0.0.3 and mysql2-0.3.11-x86-mingw32 are there and
the database.yaml file is correctly updated.
The missing piece is here:http://www.mohanarun.com/how-to-install-mysql-adapter-ruby-gem-in-windows/
After restarting the MySQL server and update the gem file as stated in the above URL. It works.
I hope this will work for you.

MySQL Gem for Ruby On Rails

I have searched everywhere and no ones solutions solve my problem. I have built rails apps using SQLite but not MySQL. For this particular project, I need MySQL. When I attempt to boot the server I get an error, so I attempt to install the gems for MySQL and get another error. Does anyone have any insight? Thank you!
rails server
Could not find gem 'mysql2 (>= 0)' in any of the gem sources listed in your Gemfile.
sudo gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/ext/mysql2/gem_make.out
I had this problem. You need to install the mysql gem with native extensions.
The line you're probably looking for is this:
$ ARCHFLAGS="-arch x86_64" gem install mysql2 --version '~> 0.2.7' -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Full write up on getting it going here: http://softwaregravy.com/mysql-on-os-x-rails-3-0-7/