Unable to install "mysql2" gem on Linux (CentOS) - mysql

I am unable to install the "mysql2" gem on my CentOS linux machine.
I recently install mysql following the following tutorial: http://www.rackspace.com/knowledge_center/article/installing-mysql-server-on-centos
When I try to download "mysql2" gem I get the following log:
[root#vc2cmmka035538n ruby]# gem install mysql2
ERROR: Could not find a valid gem 'mysql2' (>= 0) in any repository
ERROR: Possible alternatives: mysql
Environment info:
Rails 3.2.3
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
gem -v 1.8.24

From their github page, quoted
This gem links against MySQL's libmysqlclient C shared library. You may need to install a package such as libmysqlclient-dev, mysql-devel, or other appropriate package for your system.
So, you might wanna install those packages first. Then you can even manually compile the gem if you still face the problem.
https://github.com/brianmario/mysql2
If mysql repo is disabled on your system, here is the link about installing them
http://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/linux-installation-yum-repo.html

Related

Rails 5 and Ruby 2.3.3 Failed to load libmysql.dll

Getting below error message logged in the console while starting the server for an application created with mysql database.
Failed to load libmysql.dll from C:\RailsInstaller\Ruby2.3.0\lib\ruby\gems\2.3.0\gems\mysql2-0.4.7-x86-mingw32\vendor\libmysql.dll
Environment Details :
Window 7 64 bit
Rails 5.0.4
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
mysqld Ver 5.7.18 for Win64 on x86_64 (MySQL Community Server (GPL))
Post install message from mysql2 ruby gem received below message on the console.
You've installed the binary version of mysql2.
It was built using MySQL Connector/C version 6.1.10.
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.10-win32.zip
This gem *includes* vendor/libmysql.dll with redistribution notice in vendor/README.
I have tried the solution from here but did not work.
Any help appreciated, thanks in advance.
Downgrading mysql2 rubygem from version 0.4.7 to 0.3.21 solved my issue.
Below steps I followed
rails new blog -d mysql # created application with mysql as database
gem uninstall mysql2 #uninstalled mysql2-0.4.7
Gemfile :
gem 'mysql2', '0.3.21' #Gemfile changed mysql2 version to 0.3.21
bundle update mysql2 #installed mysql2-0.3.21 version
Just as an update to this thread, specifying the platform of the gem did the job for me;
gem uninstall mysql2
gem install mysql2 --platform=ruby
And here is my version details:
Windows OS
Ruby 2.5.0p0 (2017-12-25 revision 61468) [i386-mingw32]
Rails 5.1.6
Gemfile:
gem 'mysql2', '0.5.1'

how to make the ruby on rails with mysql environment in ubuntu 11.04

how to make the ruby on rails with mysql environment in ubuntu 11.04.
I use the
sudo apt-get install ruby
sudo apt-get install mysql-server
Then I try
gem install rails
But I do not know to to install the mysql adapter?
Is there a document which I can follow?
Update:
Now,I install the gems use
gem install rails.
There are no errors.
However when I run
rails -v
I got 'rails' is not installed,you can typing sudo apt-get install rails
However when I change to the rails bin directory,and use the ruby to run the rails script,I can get the version:
xx#mac:/$ rails -v
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
xx#mac:/$ cd /var/lib/gems/1.8/bin/
xx#mac:/var/lib/gems/1.8/bin$ ruby rails -v
Rails 3.2.1
xx#mac:/var/lib/gems/1.8/bin$
So,it seems that this is caused that the 'rails' can not be run directly,how to fix it?
You'd better use RVM to manage your Rubies and Gems instead of the distro's Ruby.
See RVM documentation : http://www.beginrescueend.com/rvm/basics/
As soon as you have RVM and a Ruby interpreter installed, install the rails gem (with MRI 1.9.2 and a gemset called "your_gemset") :
rvm use 1.9.2
rvm gemset use your_gemset
gem install rails
Generate your Rails project, then update the Gemfile (in your project directory) : remove the sqlite3 adapter entry and replace it with the mysql2 adapter :
# Gemfile
# gem 'sqlite3'
gem 'mysql2'
Finally, edit your database.yml file with your MySQL configuration.
You may need to include dependencies:
gem install rails --include-dependencies
The following link is a good resource.
http://www.tutorialspoint.com/ruby-on-rails/rails-database-setup.htm

installing rails

I'm trying to install rails and its giving me a headache, I can't seem to get it working. I'm using osx 10.5 and I used macports to get rub,rails and ruby gems installed in opt/local/bin but mysql is getting frustrating, I have it working in a mamp directory, I also tried installing it via the dmg, which works but the profile won't work everytime I try to load it it says "Could not load mysql preference pane" and if I try in terminal type which mysql I get: /usr/local/mysql/bin/mysql but if I try to check the version I get :
mysql -version
dyld: unknown required load command 0x80000022
Trace/BPT trap
I'm trying to launch webrick inside a rails app i've created but when I run "rails server" I get the error:
Could not find gem 'mysql2 (>= 0)' in any of the gem sources listed in your Gemfile.
I have no idea whats going on
Isn't there an easy way to install rails like MAMP?
UPDATE:
ok I got mysql installed, apprently there is a bug with the latest version causing a problem with the preference pane. mysql is installed in
/usr/local/mysql/bin/mysql
2 questions I have about this. Is this the right path should it not be in /usr/local/mysql ?
and the second is how would I link this to my ruby gem? is this right:
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
or
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql/bin/mysql
I suggest you use HomeBrew to install mysql or ruby instead of MacPorts.
Could not find gem 'mysql2 (>= 0)' in any of the gem sources listed in your Gemfile.
This error is caused because rails requires the mysql2 gem to connect to mysql. All you have to do in include
gem mysql2
to the gemfile in the root directory of the rails app and do a bundle install
If you just trying out rails then you might as well use the default sqlite3 database forget about mysql.
The installation path is correct.
Installing the mysql gem is slightly more complicated than necessary since the installation automatically tries generating both 32bit and 64bit versions.
Assuming you have installed the 64 bit binary package, try the following (from the bash command line):
ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
However, it is recommended that you do not mess with the OSX ruby installation and use rvm (The Ruby Version Manager) to create a customized ruby environment. You can find a good tutorial for Rails and RVM here.

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/

Problem with rake db:migrate

When I try rake db:migrate, I get the following error:
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql
And when I try to "gem install mysql"
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
Can't find header files for ruby.
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
I checked the rubygems folder and mysql gem has been installed. Any ideas? Cheers
This should sort it out on Ubuntu:
sudo aptitude install libmysqlclient-dev build-essential
Then install the gem again. You may need to delete the /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 folder if it craps out.
I hope that helps.
The gem hasn't actually been installed. You are missing either the ruby development files, mysql developer files, or linux build essentials. Since you are asking, I'll assume you are on a linux distribution with a package manager; install the corresponding packages.
As Sleepycat suggested, most probably you need the dev libraries for MySQL.
On Fedora / CentOS this should solve your problem:
yum install mysql-devel
gem install mysql