Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when starting rails server #717

Closed
lalithr95 opened this issue Jan 1, 2016 · 10 comments
Closed

Error when starting rails server #717

lalithr95 opened this issue Jan 1, 2016 · 10 comments

Comments

@lalithr95
Copy link

There was a problem when I start the server
'rails s' throws me with following error

Starting Rails4
/Users/Lalith/.rvm/gems/ruby-2.1.5/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'mysql2'. (Bundler::GemRequireError)
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
    from /Users/Lalith/Documents/Intern/hackerrank/config/application.rb:7:in `<top (required)>'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:79:in `require'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:79:in `block in server'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:76:in `server'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/Lalith/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands.rb:17:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

bundle install works
Mysql 5.7.10 installed through brew
Rails 4.1.7
mysql2 gem 0.3.16

@sodabrew
Copy link
Collaborator

sodabrew commented Jan 1, 2016

You may need mysql2 0.3.17 or higher for compatibility with MySQL 5.7.

@lalithr95
Copy link
Author

@sodabrew Worked with lower version of mysql 5.6, 5.5

@AparnaDhinakaran
Copy link

@lalithr95, how did you fix the issue?

@PeterBloom
Copy link

I have the same issue. Error on 'rails s' is

`rescue in block (2 levels) in require': There was an error while trying to load the gem 'mysql2'. (Bundler::GemRequireError)

MySQL v5.6.23
gem mysql2 v0.3.15
rails v3.2.21
bundler v1.11.2

@sodabrew
Copy link
Collaborator

sodabrew commented Jan 6, 2016

@PeterBloom Try just loading mysql2 within your gem set to see if there's a more detailed message. Something like bundle exec ruby -r mysql2.

@lalithr95
Copy link
Author

@PeterBloom try this as well
Use mysql2 gem with latest version 0.4.2.
If you are not allowed to change versions in the Gemfile then uninstall mysql from brew

brew uninstall mysql

Now install mysql5.6 version using brew

brew tap homebrew/versions

Then install mysql56 or something similar formula

brew install mysql56

@PeterBloom
Copy link

Thanks @sodabrew and @lalithr95,

My setup is a bit complex. In my local environment, I use a Docker server running MySQL 5.6.27. (This is to emulate part of a production db architecture.) My origin/master repo Gemfile.lock (shared by coworkers) calls for mysql2 gem v0.3.15.

When running 'rails s' with this gem version, I received the error "uninitialized constant Mysql2::Client::SECURE_CONNECTION (NameError)". I am using ruby 2.1.5, rails 3.2.21, bundler 1.10.6 in this environment.

After some research and a few tries, I was able to get a good rails server start with the mysql2 v0.3.18 gem. I had to change my local branch Gemfile.lock to call for this version. Newer versions of mysql2 gem (such as v0.4.2) failed (I think they may only support MySQL >=5.7).

I'd like to upgrade the versioned Gemfile.lock to v0.3.18, but don't want to create problems for others, or the production environment.

Please let me know if you have any comments on this issue or have experienced something similar. Thanks!

@sodabrew
Copy link
Collaborator

sodabrew commented Jan 8, 2016

In order to use mysql2 0.4.x, you need Rails 4.2.5 or higher. It otherwise works with all versions of MySQL >= 5.0.

If you use the MySQL 5.7 client libraries, then you need mysql2 0.3.17 or higher. You mention that you're using MySQL 5.6.27, but I suspect you may have a different client library or newer headers in your docker image.

@lalithr95
Copy link
Author

@PeterBloom Have a look at this issue #603 for Mysql2::Client::SECURE_CONNECTION error.

@vemarav
Copy link

vemarav commented Apr 21, 2016

There was an issue in mysql2 0.4.0 and later versions.

Try using these 
1)gem list mysql2
1. mysql2-0.3.20
2. mysql2-0.4.3
3. All versions

2)gem uninstall mysql2

3)Now change Gemfile 
     gem mysql2,'0.3.14'

4)bundle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants