Advice needed --- Best way to get mysql2 gem installed to interact with Mysql Database?

Hi Group,
I’ve got mysql database installed and the server running on a Mac Pro with latest mountain lion setup 10.8.3.

I’m able to use mysql tools like mysql, mysqladmin to converse with it. :}

I use RVM’s scripts to fetch gems.

I’ve visited RVM’s website but their advise to get “mysql gem loaded” does the same thing as below aborted output!

I’m not sure that this website is being maintained anymore as their copyright notice is 2011.

What/how suggestions appreciated to get this mysql2 gem installed so that i can use rails/ruby against this database?

My ROR config:

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]

Rails 3.2.12

RVM gem managed

So far Macport seems to work to install mysql and gen/install the mysql2 gem. I’ve not tried this gem yet as i’m still using RVM.

I don’t believe this is the latest mysql release by Macport.

It goes against Mysql’s website advise to install it by DMG route for Mac which I did with the latest stable 64 bit libraries/server.

Thanks for your help in trying to resolve this issue.

Dave

The aborted output from gem install mysql2.

Both ways attempted: gem install mysql2 and with the option --with-mysql-config=/usr/local/mysql/bin/mysql_config

gem install mysql2 – --with-mysql-config=/usr/local/mysql/bin/mysql_config

Building native extensions. This could take a while…

ERROR: Error installing mysql2:

ERROR: Failed to build gem native extension.

/Users/bone_david/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config

checking for rb_thread_blocking_region()… yes

checking for rb_wait_for_single_fd()… yes

checking for mysql.h… no

checking for mysql/mysql.h… no

The error message is pretty clear. Did your MySQL DMG installation
include header files? Can you find mysql.h on your system?

I recently installed all this on a new macbook pro, with mountain lion
as of last october. Steps I took were:

1. Install and set up homebrew package manager [http://brew.sh/]
2. Install mysql via homebrew
3. Install rvm, ruby, gem, rails [http://rvm.io]
4. Create rails app [guides.rubyonrails.org]
5. ???
6. PROFIT

Hi Hassan,

The file is in the include subfolder.

ls -al /usr/local/mysql/include

total 1136

drwxr-xr-x 45 root wheel 1530 5 Apr 10:23 .

drwxr-xr-x 17 root wheel 578 11 May 12:53 …

-rw-r–r-- 1 root wheel 4507 5 Apr 08:27 big_endian.h

-rw-r–r-- 1 root wheel 5196 5 Apr 08:27 byte_order_generic.h

-rw-r–r-- 1 root wheel 4536 5 Apr 08:27 byte_order_generic_x86.h

-rw-r–r-- 1 root wheel 4016 5 Apr 08:27 byte_order_generic_x86_64.h

-rw-r–r-- 1 root wheel 31232 5 Apr 08:27 my_pthread.h

-rw-r–r-- 1 root wheel 41163 5 Apr 08:27 my_sys.h

-rw-r–r-- 1 root wheel 2817 5 Apr 08:27 my_xml.h

drwxr-xr-x 25 root wheel 850 5 Apr 10:23 mysql

-rw-r–r-- 1 root wheel 29058 5 Apr 08:27 mysql.h

-rw-r–r-- 1 root wheel 23605 5 Apr 08:27 mysql_com.h

-rw-r–r-- 1 root wheel 1313 5 Apr 08:27 mysql_com_server.h

-rw-r–r-- 1 root wheel 1185 5 Apr 08:27 mysql_embed.h

-rw-r–r-- 1 root wheel 2168 5 Apr 08:27 mysql_time.h

-rw-r–r-- 1 root wheel 854 5 Apr 09:53 mysql_version.h

-rw-r–r-- 1 root wheel 91661 5 Apr 09:53 mysqld_ername.h

-rw-r–r-- 1 root wheel 33795 5 Apr 09:53 mysqld_error.h

-rw-r–r-- 1 root wheel 23633 5 Apr 08:27 plugin.h

-rw-r–r-- 1 root wheel 3996 5 Apr 08:27 plugin_audit.h

-rw-r–r-- 1 root wheel 7589 5 Apr 08:27 plugin_ftparser.h

-rw-r–r-- 1 root wheel 1576 5 Apr 08:27 plugin_validate_password.h

-rw-r–r-- 1 root wheel 4834 5 Apr 08:27 sql_common.h

-rw-r–r-- 1 root wheel 13273 5 Apr 09:53 sql_state.h

-rw-r–r-- 1 root wheel 1350 5 Apr 08:27 sslopt-case.h

-rw-r–r-- 1 root wheel 2556 5 Apr 08:27 sslopt-longopts.h

-rw-r–r-- 1 root wheel 1367 5 Apr 08:27 sslopt-vars.h

-rw-r–r-- 1 root wheel 2278 5 Apr 08:27 typelib.h

I see another /usr/local/mysql/include/mysql subfolder.

ls -al /usr/local/mysql/include/mysql/

total 312

drwxr-xr-x 25 root wheel 850 5 Apr 10:23 .

drwxr-xr-x 45 root wheel 1530 5 Apr 10:23 …

-rw-r–r-- 1 root wheel 333 5 Apr 08:27 client_authentication.h

-rw-r–r-- 1 root wheel 5595 5 Apr 08:27 client_plugin.h

-rw-r–r-- 1 root wheel 1986 5 Apr 08:27 client_plugin.h.pp

-rw-r–r-- 1 root wheel 1198 5 Apr 08:27 get_password.h

-rw-r–r-- 1 root wheel 1387 5 Apr 08:27 innodb_priv.h

-rw-r–r-- 1 root wheel 23633 5 Apr 08:27 plugin.h

-rw-r–r-- 1 root wheel 3996 5 Apr 08:27 plugin_audit.h

-rw-r–r-- 1 root wheel 10174 5 Apr 08:27 plugin_audit.h.pp

-rw-r–r-- 1 root wheel 3409 5 Apr 08:27 plugin_auth.h

-rw-r–r-- 1 root wheel 10159 5 Apr 08:27 plugin_auth.h.pp

-rw-r–r-- 1 root wheel 4431 5 Apr 08:27 plugin_auth_common.h

-rw-r–r-- 1 root wheel 7589 5 Apr 08:27 plugin_ftparser.h

-rw-r–r-- 1 root wheel 9058 5 Apr 08:27 plugin_ftparser.h.pp

-rw-r–r-- 1 root wheel 1576 5 Apr 08:27 plugin_validate_password.h

drwxr-xr-x 10 root wheel 340 5 Apr 10:23 psi

-rw-r–r-- 1 root wheel 1678 5 Apr 08:27 service_my_plugin_log.h

-rw-r–r-- 1 root wheel 3361 5 Apr 08:27 service_my_snprintf.h

-rw-r–r-- 1 root wheel 5348 5 Apr 08:27 service_mysql_string.h

-rw-r–r-- 1 root wheel 4379 5 Apr 08:27 service_thd_alloc.h

-rw-r–r-- 1 root wheel 3675 5 Apr 08:27 service_thd_wait.h

-rw-r–r-- 1 root wheel 1869 5 Apr 08:27 service_thread_scheduler.h

-rw-r–r-- 1 root wheel 1124 5 Apr 08:27 services.h

-rw-r–r-- 1 root wheel 5053 5 Apr 08:27 thread_pool_priv.h

Is it possible that the install somehow thinks it should use this subfolder? If so how to declare to the “gem install” to use /usr/local/mysql/include and not its subfolder …include/mysql?

Dave

That seems like it should have been found. Did you say you were
using `rvm gem install ....` for this? If so, what happens if you just
try `gem install mysql2` ? If that fails, try it with --verbose and gist
the result.

Hi Hassan,

Here’s the same reult’s output with --verbose.

I tried it without and with the --with-mysql-config parameter;

Dave

davids-MacBook-Pro:sailing_oli_bk31mar2013pg bone_david$ gem install mysql2 --verbose – --with-mysql-config=/usr/local/mysql/bin/mysql_config

GET http://rubygems.org/latest_specs.4.8.gz

302 Moved Temporarily

GET http://production.s3.rubygems.org/latest_specs.4.8.gz

304 Not Modified

GET http://rubygems.org/latest_specs.4.8.gz

302 Moved Temporarily

GET http://production.s3.rubygems.org/latest_specs.4.8.gz

304 Not Modified

Installing gem mysql2-0.3.11

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/.gitignore

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/.rspec

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/.rvmrc

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/.travis.yml

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/CHANGELOG.md

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/Gemfile

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/MIT-LICENSE

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/README.md

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/Rakefile

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/active_record.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/active_record_threaded.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/allocations.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/escape.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/query_with_mysql_casting.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/query_without_mysql_casting.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/sequel.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/setup_db.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/benchmark/threaded.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/examples/eventmachine.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/examples/threaded.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/client.c

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/client.h

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/extconf.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/mysql2_ext.c

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/mysql2_ext.h

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/result.c

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/result.h

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/wait_for_single_fd.h

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/client.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/em.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/error.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/result.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/version.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/mysql2.gemspec

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/spec/em/em_spec.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/spec/mysql2/client_spec.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/spec/mysql2/error_spec.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/spec/mysql2/result_spec.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/spec/rcov.opts

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/spec/spec_helper.rb

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/tasks/benchmarks.rake

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/tasks/compile.rake

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/tasks/rspec.rake

/Users/bone_david/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/tasks/vendor_mysql.rake

Building native extensions. This could take a while…

ERROR: Error installing mysql2:

ERROR: Failed to build gem native extension.

/Users/bone_david/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config

checking for rb_thread_blocking_region()… yes

checking for rb_wait_for_single_fd()… yes

checking for mysql.h… no

checking for mysql/mysql.h… no

? Strange. I'd suggest you 1) check the mkmf.log file referenced
above on the off-chance it has more enlightening information, and
2) run mysql_config manually to see what it says.

And finally, if you're not making progress there, just forget the DMG
install and use the MacPorts version (which I do) because, really,
who cares? For development the exact version of MySQL probably
isn't critical. Before you go to production you'll want a staging server
matching your production environment set up to test on anyway.

HTH,

Thanks for your help Hassan.

Here’s the mfmk.log showing what threw the compile error.

I’ll try 2) run mysql_config manually to see what it says.

and experiment with the compile stream to see if i can get it going

Would it be appropriate to pass this problem onto the Rubygem team, and/or Mysql/Oracle people?

Your suggestion to use MacPort will be my last resort

Thanks again

Dave

davids-MacBook-Pro:sailing_oli_bk31mar2013pg bone_david$ cat /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/mkmf.log

have_func: checking for rb_thread_blocking_region()… -------------------- yes

"/usr/bin/gcc-4.2 -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin12.2.0 -I/usr/local/rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/include -fno-common -pipe conftest.c -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p194/lib -L. -L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib -lruby.1.9.1 -lpthread -ldl -lobjc "

ld: warning: directory not found for option ‘-L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib’

checked program was:

/* begin */

1: #include “ruby.h”

2:

3: int main() {return 0;}

/* end */

"/usr/bin/gcc-4.2 -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin12.2.0 -I/usr/local/rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/include -fno-common -pipe conftest.c -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p194/lib -L. -L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib -lruby.1.9.1 -lpthread -ldl -lobjc "

ld: warning: directory not found for option ‘-L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib’

checked program was:

/* begin */

1: #include “ruby.h”

2:

3: /top/

4: int main() {return 0;}

5: int t() { void ((volatile p)()); p = (void (()()))rb_thread_blocking_region; return 0; }

/* end */

Here's the mfmk.log showing what threw the compile error.
I'll try 2) run mysql_config manually to see what it says.
and experiment with the compile stream to see if i can get it going

Would it be appropriate to pass this problem onto the Rubygem team, and/or
Mysql/Oracle people?

No, not really :slight_smile:

ld: warning: directory not found for option '-L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib'

? That seems really strange; what version of RVM are you using?

which rvm

/Users/bone_david/.rvm/bin/rvm

/Users/bone_david/.rvm/bin/rvm -v

rvm 1.20.5 (stable) by Wayne E. Seguin <>, Michal Papis <>

Dave

More recent than mine. I would probably ask about that strange
warning referencing '/Users/mpapis' on the irc channel.

Also, I just realized your Ruby version is pretty old; you might want
to try updating that as well (current 1.9.3 MR patchlevel is p392).

HTH, and good luck!

Thks Hassan for your help.

I’ll try the irc channel though this will be my first experience.

Hopefully this will correct the problem.

I’ll upgrade ruby as suggested

Dave

Hassan,

My IRC/#rvm session today echoes your advice to use macports/mysql instead of rvm.

As rvm is just a conduit where the install/compile of gems is outside its jurisdiction regarding correctness.

I suggested in the irc/#rvm session that rvm’s website be corrected regarding their mysql advice/suggestions.

i.e. to use macport instead of rvm to install the mysql2 gem with its appropriate mysql database rather than the dmg route.

HTH others like myself. Again thk u

Dave

The problem with mysql2 still outstanding using the latest mysql.dmg

Wait, what? I think you're still confused. Using rvm to manage your
ruby versions and gemsets has nothing whatsoever to do with how
you install server software like MySQL on your system.

I suggested that if a MacPorts install of MySQL provided the header
files you need to install the mysql *gem* and just worked, then you
might as well go with that and be done.

So you can get on to the fun part of developing with Rails :slight_smile:

BTW, do you have a link to the rvm site where it discusses MySQL
installation? I've never seen that.

Yes to your statement on rvm not being a fetcher of various packages. I expressed it improperly rather then being confused :{

Here is the link from rvm on how to get the mysql database from mysql site with their recommendation which i followed leading to this raised issue:

https://rvm.io/integration/databases/

Under OSX.

As per previous note, I believe rvm’s advice will be corrected in the above link as ‘current Mysql downloads’ causes the mysql2 gem problem when using rvm.

FWIW:

The mysql2 gem problem is NOT caused by rvm but in the downloaded files supplied by Mysql site’s ‘download’.

So the current route is use Macports to install mysql it rather than Mysql website download.(as per advice from this group + rvm/irc session)

The current Mysql database download works well but has problems when Rails interfaces to it via mysql2 gem.

This still leaves the issue outstanding regarding rails/mysql via ‘Mysql download’ where one wants to use the latest Mysql database version.

Dave