2

I have an error while trying to 'bundle install' when listing 'mysql2' on the Gemfile on OSX Lion. I'm currenly building an app with Rails. If I run 'bundle install', it hangs forever. First I tried to fix the issue by modifying the gem file to 'gem 'mysql2', :git => 'git://github.com/sodabrew/mysql2.git', :ref => 'a2800f'', as suggested here: https://github.com/brianmario/mysql2/pull/654. The infinite loop got fixed, I ran 'bundle install' sucessfully but when I run 'rake db:create', I got this error:

rake aborted!
LoadError: dlopen(/Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
Referenced from: /Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle
/Users/macbook/Desktop/tutorial/billingleap2/moviestore/config/application.rb:7:in `<top (required)>'
/Users/macbook/Desktop/tutorial/billingleap2/moviestore/Rakefile:4:in `<top (required)>'

I also try to 'brew install mysql' and it worked, but then on 'rake db:create', I got this error:

#<Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)>
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"moviestore_development"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)
#<Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)>
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8","pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"moviestore_test"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)

So then I 'brew uninstall mysql' and that problem was gone, but now I have the first one.

Trying 'gem install mysql2 -v '0.3.19'' also hangs.

What could be the problem?

Cherenkov
  • 485
  • 1
  • 8
  • 16
  • please paste your Gemfile and gemfile.lock here – K M Rakibul Islam Aug 20 '15 at 23:12
  • 1
    Is mysql server process running and accepting connections? The error message suggests that no process is accepting connections. Two guesses: 1) there is no mysql daemon process running 2) there is a mysql daemon process running but it does not accept any local connections. I think 1) is more likely. How did you start mysql after installing it? – mkro Aug 21 '15 at 00:20
  • Here is the Gemfile: http://pastie.org/10365361 and here is the gemfile.lock: http://pastie.org/10365363 – Cherenkov Aug 21 '15 at 01:46

1 Answers1

3

As you are using bundler, you have to fix the first issue (why bundle install is failing) and install the mysql2 gem using bundler. There must have some gem dependency issue that you need to look at.

And, you should run: bundle exec rake db:migrate as you are using bundler and Gemfile etc. that will ensure your rake task runs in the context of the current project.

Update: 1

If you already ran: bundle install successfully and installed the mysql2 gem successfully, then try running:

`bundle exec rake db:create`

If this causes you the specified error (which means your libmysqlclient library is not loading for some reason):

rake aborted!
LoadError: dlopen(/Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
Referenced from: /Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle
/Users/macbook/Desktop/tutorial/billingleap2/moviestore/config/application.rb:7:in `<top (required)>'
/Users/macbook/Desktop/tutorial/billingleap2/moviestore/Rakefile:4:in `<top (required)>'

then you should look at this answer and this one too which have some prescribed solutions for similar issue. Try those see if that works.

Update: 2

So, mysql gem has some development dependencies which needs to be installed in your system before you can actually use mysql. Do the following:

sudo gem install mysql-server mysql-client
sudo gem install libmysql-ruby libmysqlclient-dev
sudo gem install mysql

And, then try again:

bundle install

Update: 3

First, to find your socket file:

mysqladmin variables | grep socket

It will give you something like this:

| socket                                            | /tmp/mysql.sock

Then, add a line to your config/database.yml:

development:
  adapter: mysql2
  host: localhost
  username: root
  password: xxxx
  database: xxxx
  socket: /tmp/mysql.sock
Community
  • 1
  • 1
K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
  • Hi, Rakibul! Thanks so much! ;) This is what is failing while `bundle install`: `checking for mysql_query() in -lmysqlclient... no`. I don't anymore have mysql install on my machine. Maybe the problem is that I installed it and uinstalled it with brew? – Cherenkov Aug 21 '15 at 01:42
  • do you have the project on github? – K M Rakibul Islam Aug 21 '15 at 03:04
  • @Sofía please try my Update: 2 and see if that fixes your issue. Let me know! – K M Rakibul Islam Aug 21 '15 at 03:12
  • Thanks Rakibul! I have been able to install mysql and also to `bundle install`. But now when `bundle exec rake db:create`, I got http://pastie.org/10365507 – Cherenkov Aug 21 '15 at 04:50
  • awesome. we are very close now. You just need to start your local mysql server – K M Rakibul Islam Aug 21 '15 at 04:52
  • Ok, I know what happened. I needed to start the server in order to make the migration. I run `mysql.server start`, and it got fixed! :) Thanks so much! – Cherenkov Aug 21 '15 at 04:54
  • 1
    I also installed mysql with brew: `brew install mysql` and then (in Gemfile) `gem 'mysql2', '~> 0.3.11'` and then `bundle install`. Sucess! – Cherenkov Aug 21 '15 at 04:55
  • Yes, exactly, you needed to start your mysql server. Awesome, all is good, right? – K M Rakibul Islam Aug 21 '15 at 04:56
  • 1
    Yeah! I feel so dummy right now.. but I guess you learn through mistakes. Thanks so much! Everything is great! – Cherenkov Aug 21 '15 at 04:58