Ruby can not require mysql - 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.

Related

Installing Mysql gem - failure to build native extension

I have tried to install mysql on windows 7 (x64), but it output an error:
Failed to build gem native extension.
You have to install mysql client library:
http://dev.mysql.com/downloads/connector/c/
1: add gem 'mysql2' in Gemfile
2: remove Gemfile.lock
3: run bundle install
Would work !!!

Rails: bundle doesn't show installed mysql2 gem

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'

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

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

Error with mysql2 gem loading Rails env on OSX: "Symbol not found: _rb_prohibit_interrupt"

I'm on OSX 10.7.5
I'm setting up an existing Rails 3 app
I've got the 64-bit dmg package of MySQL (v5.5.28) installed
I've installed the mysql2 gem (v0.3.11) as part of the app bundle
Whenever i try to load the rails env (raking, loading console, etc.), I get this:
rake aborted!
dlopen(/Users/daretorant/.rvm/gems/ruby-1.9.3-p194#amp/bundler/gems/mysql2-f4d004ac5194/lib/mysql2/mysql2.bundle, 9): Symbol not found: _rb_prohibit_interrupt
Referenced from: /Users/daretorant/.rvm/gems/ruby-1.9.3-p194#amp/bundler/gems/mysql2-f4d004ac5194/lib/mysql2/mysql2.bundle
Expected in: flat namespace
in /Users/daretorant/.rvm/gems/ruby-1.9.3-p194#amp/bundler/gems/mysql2-f4d004ac5194/lib/mysql2/mysql2.bundle - /Users/daretorant/.rvm/gems/ruby-1.9.3-p194#amp/bundler/gems/mysql2-f4d004ac5194/lib/mysql2/mysql2.bundle
/Users/daretorant/.rvm/gems/ruby-1.9.3-p194#amp/bundler/gems/mysql2-f4d004ac5194/lib/mysql2.rb:9:in require'
/Users/daretorant/.rvm/gems/ruby-1.9.3-p194#amp/bundler/gems/mysql2-f4d004ac5194/lib/mysql2.rb:9:in'
.........
Things I've tried:
other versions of mysql2
fresh install of mysql itself
cleaning my gemset
cleaning rvm
pulling hair out
Help?
I have just run into this issue. What had helped me was installing the 64bit version of the mysql2 gem, like this:
$ env ARCHFLAGS="-arch x86_64" gem install mysql2

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.