2
votes

I installed ruby and ruby gems through macport but the gem list does not include mysql2. So how would I get mysql2 gem installed inside my gem list which is inside "/opt/local/bin/gem"

Also, what is the mysql2 gem? I have mysql gem and only want to use mysql, not really sure what it means by mysql2. It gives my a mysql2 error when I try to launch webrick on an app.

UPDATE: I ran sudo gem install mysql2 and got the following:

Building native extensions. This could take a while... Successfully installed mysql2-0.2.7 1 gem installed Installing ri documentation for mysql2-0.2.7...

Enclosing class/module 'mMysql2' for class Client not known

Enclosing class/module 'mMysql2' for class Result not known Installing RDoc documentation for mysql2-0.2.7...

Enclosing class/module 'mMysql2' for class Client not known

Enclosing class/module 'mMysql2' for class Result not known

Assuming that mysql2 installed, even though the docs didn't I get the following error when I try to launch webrick in my app.

rails server:

/opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle: dlopen(/opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle Reason: image not found - /opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle from /opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2.rb:8 from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in require' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in require' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in each' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in require' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in each' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in require' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in require' from /Users/summer/Sites/simple_cms/config/application.rb:7 from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:28:in require' from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:28 from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:27:in tap' from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:27 from script/rails:6:inrequire' from script/rails:6

2
You are missing libmysqlclient-dev headers try and search for that library in macports. That is what i had to install on my Ubuntu in order to install the gem.sirfilip

2 Answers

2
votes

In order to perform a search for remote gems that are available run the command gem search mysql2 -r (note the -r at the end)

* REMOTE GEMS *

activerecord-mysql2legacydb-adapter (0.2.0) activerecord-mysql2spatial-adapter (0.3.2) em_mysql2_connection_pool (0.0.5) ghazel-mysql2 (0.2.6.3) mysql2 (0.2.7, 0.2.6 x86-mingw32 x86-mswin32-60) mysql2_bigint (0.2.6.1) mysql2_model (0.1.2) mysql2mysql (0.0.2) mysql2psql (0.1.0) mysql2xxxx (0.0.4)

from the list of gems you should pick mysql2 and run sudo gem install mysql2

2
votes

As far as I know, one of the differences between the two gems (mysql and mysql2) is that mysql2 works better with UTF-8. Here is an article about it.

To install your mysql2 gem, just run:

gem install 'mysql2'