mysql2: uninitialized constant Mysql2::Client::SECURE_CONNECTION (NameError)

I’m trying to get my application running on a windows server but when running rails server I get the below error. I have installed MySQL and ran the bundle install.

C:\myapp> rails server -e production
=> Booting WEBrick
=> Rails 4.1.2.rc1 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
C:/Ruby22/lib/ruby/gems/2.2.0/gems/mysql2-0.3.16/lib/mysql2/client.rb:12:in `<class:Client>': uninitialized constant Mysql2::Client::SECURE_CONNECTION (NameError)
C:/Ruby22/lib/ruby/gems/2.2.0/gems/mysql2-0.3.16/lib/mysql2/client.rb:12:in `<class:Client>': uninitialized constant Mys
ql2::Client::SECURE_CONNECTION (NameError)
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/mysql2-0.3.16/lib/mysql2/client.rb:2:in `<module:Mysql2>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/mysql2-0.3.16/lib/mysql2/client.rb:1:in `<top (required)>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/mysql2-0.3.16/lib/mysql2.rb:10:in `<top (required)>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activerecord-4.1.2.rc1/lib/active_record/connection_adapters/mysql2_adap
ter.rb:4:in `<top (required)>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activerecord-4.1.2.rc1/lib/active_record/connection_adapters/connection_
specification.rb:188:in `spec'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activerecord-4.1.2.rc1/lib/active_record/connection_handling.rb:50:in `e
stablish_connection'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activerecord-4.1.2.rc1/lib/active_record/railtie.rb:129:in `block (2 lev
els) in <class:Railtie>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-4.1.2.rc1/lib/active_support/lazy_load_hooks.rb:38:in `ins
tance_eval'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-4.1.2.rc1/lib/active_support/lazy_load_hooks.rb:38:in `exe
cute_hook'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-4.1.2.rc1/lib/active_support/lazy_load_hooks.rb:28:in `blo
ck in on_load'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-4.1.2.rc1/lib/active_support/lazy_load_hooks.rb:27:in `eac
h'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-4.1.2.rc1/lib/active_support/lazy_load_hooks.rb:27:in `on_
load'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activerecord-4.1.2.rc1/lib/active_record/railtie.rb:118:in `block in <cl
ass:Railtie>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/initializable.rb:30:in `instance_exec'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/initializable.rb:30:in `run'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/initializable.rb:55:in `block in run_initia
lizers'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:345:in `each'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:345:in `call'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
        from C:/Ruby22/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/initializable.rb:54:in `run_initializers'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/application.rb:300:in `initialize!'
        from C:/myapp/config/environment.rb:5:in `<top (required)>'
        from C:/myapp/config.ru:3:in `block in <main>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
        from C:/myapp/config.ru:in `new'
        from C:/myapp/config.ru:in `<main>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'

        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/commands/server.rb:50:in `app'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rack-1.5.2/lib/rack/server.rb:250:in `start'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/commands/server.rb:69:in `start'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/commands/commands_tasks.rb:81:in `block in
server'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/commands/commands_tasks.rb:76:in `tap'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/commands/commands_tasks.rb:76:in `server'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/commands/commands_tasks.rb:40:in `run_comma
nd!'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-4.1.2.rc1/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 31 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Quick brew bash rundown for those coming from SEO channel:

$ brew tap homebrew/versions
$ brew update
$ brew uninstall mysql mysql2 # probs auto updated to 5.7
$ brew install mysql56 # 5.6 locked version
# copy in the launchctrl output
$ gem uninstall mysql mysql2 # uninstall legacy gems
$ bundle install # to install / rebuild new refs

@zouqilin As I wrote above, you will need the mysql2 gem version 0.3.17 or higher to run with MySQL 5.7.

@tomfuertes mysql2 gem 0.3.17 and 0.2.24 and above support MySQL 5.7. Directing people to downgrade to MySQL 5.6 is not necessary.

Please use mysql2 0.3.18 for more reliable windows builds.

I ran into this issue several times and found an easier fix which is quickly editing client.rb in the error message and changing line :connect_flags => REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION, to :connect_flags => REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41,

Thanks, changing to mysql2 gem to 0.2.24 worked !!

@sodabrew Thanks. Finding the right version of mysql2 was the key. “0.3.15” couldn’t handle the new mysql I homebrew installed, and “0.4…” was too new for my rails 3.2 (I think). “0.3.17” is working.

You must use mysql2 series 0.2.x with Rails 2.3.x. I believe that mysql2 version 0.2.24 contains the necessary change to work with MySQL 5.7.

Like @Arcolye the gem 'mysql2', '0.3.17' worked for me too.

@paralaks Supporting MySQL 5.7 was added in 0.3.17 and higher.

Here’s the compatibility table for Rails and mysql2 versions: https://github.com/brianmario/mysql2/blob/master/README.md#compatibility

To fix your problem you should upgrade your mysql2 gem version or downgrade MySQL.

@sodabrew 0.3.17 has done it, thanks!

I downgraded to ruby 2.0.0 and no longer receive this error. Closing