2

I want to run a rails application on my mac osx 10.9.3 and got following error:

/Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `require': Incorrect MySQL client library version! This gem was compiled for 5.5.23 but the client library is 5.6.19. (RuntimeError)
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `<top (required)>'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:76:in `require'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:72:in `each'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:72:in `block in require'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in `each'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in `require'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler.rb:132:in `require'
    from /Users/home/workSpace/RubyOnRails/simple_cms/config/application.rb:7:in `<top (required)>'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `require'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `block in server'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:8:in `require'
    from bin/rails:8:in `<main>'

I installed mysql with hombrew and it's working perfectly. I also use rbenv.

gem 'rails', '4.1.1'
gem 'mysql2'

and this is my databas.yml file

development:
  adapter: mysql2
  encoding: utf8
  database: simple_cms_development
  pool: 5
  username: root
  password: somepassword
  socket: /tmp/mysql.sock

test:
  adapter: mysql2
  encoding: utf8
  database: simple_cms_test
  pool: 5
  username: root
  password: somepassword
  socket: /tmp/mysql.sock

production:
  adapter: mysql2
  encoding: utf8
  database: simple_cms_production
  pool: 5
  username: root
  password: somepassword
  socket: /tmp/mysql.sock

How can I solve it?

aakpro
  • 1,538
  • 2
  • 19
  • 53
  • I had the same problem. I added the apt-get repository that is provided on dev.mysql.com: http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/. Please ensure that all mysql software on your computer (mysql-client, mysql-server, mysql-utilities, libmysqlclient18, etc) are all installed and updated using this repository. I then ran sudo apt-get install libmysqlclient-dev. Afterwards, I was able to successfully install the mysql2 gem. – Peter Kirby Jul 14 '14 at 14:59
  • sudo apt-get install libmysqlclient-dev on mac os x!!!! – Ruyonga Dan Dec 07 '15 at 13:27

1 Answers1

0

Headers

I was going to suggest using mysql C-connector (the recommended answer in the comments confirmed this)

We've written a tutorial on how to do this (for the typical unable to build native extensions error), but same idea

--

C-Connector

Basically, your gem just needs to interface with your system; it doesn't need need to do anything buy send queries & process the responses to your db

This means if you have a problem with your mysql version's compatibility, you'll be best installing & using a separate batch of header files (for your gem):

The way to do this is to download & install the mysql c-connector files - IMPORTANT - GET THE 32 BIT VERSION (you can either use the installer or unzip the files)

Once installed, you should install the gem with the following command:

gem install mysql2 --platform=ruby -- ‘--with-mysql-dir="YOUR_MYSQL_DIR”’

This should install the gem for you, which will allow you to interface with the MYSQL server

Richard Peck
  • 76,116
  • 9
  • 93
  • 147