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

uninitialized constant Mysql2::Client::SECURE_CONNECTION (NameError) #603

Closed
jostster opened this issue Mar 25, 2015 · 31 comments
Closed

uninitialized constant Mysql2::Client::SECURE_CONNECTION (NameError) #603

jostster opened this issue Mar 25, 2015 · 31 comments

Comments

@jostster
Copy link

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>'
@sodabrew
Copy link
Collaborator

sodabrew commented Mar 25, 2015 via email

@jostster
Copy link
Author

@sodabrew I'm using RubyInstallers and did build with gem install mysql2 -v '0.3.16' -- '--with-mysql-dir="C:/path/to/mysql"'

@jostster
Copy link
Author

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

@sodabrew
Copy link
Collaborator

sodabrew commented Mar 25, 2015 via email

@sodabrew
Copy link
Collaborator

sodabrew commented Mar 25, 2015 via email

@tomfuertes
Copy link

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

@sodabrew
Copy link
Collaborator

@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.

@mgoggin
Copy link

mgoggin commented Nov 20, 2015

@tomfuertes 👍 Thanks bro. I'm stuck on 0.3.11 and this helped me to get my app running again after I reloaded my workstation.

@augus-zz
Copy link

i occured this problems since i upgraded mysql57 ,s what should i do to solve it

@augus-zz
Copy link

mac mysql 0.3.20 rails 3.2.16

@tomfuertes
Copy link

Try gem uninstall MySQL then reinstall.

On Nov 21, 2015, at 9:24 PM, zouqilin [email protected] wrote:

mac mysql 0.3.20 rails 3.2.16


Reply to this email directly or view it on GitHub.

@sodabrew
Copy link
Collaborator

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

@augus-zz
Copy link

@sodabrew i tried mysql2 0.3.20 but the problem continued

@kimmy
Copy link

kimmy commented Dec 1, 2015

+1 @ZouQiLin

@sodabrew
Copy link
Collaborator

sodabrew commented Dec 1, 2015

It's simply not possible. The code always defines SECURE_CONNECTION: https://github.com/brianmario/mysql2/blob/0.3.x/ext/mysql2/client.c#L1381-L1388

Perhaps you are installing a new copy of the mysql2 gem and still using the old copy? Is your project using a Gemfile or Gemfile.lock with a specific and older version of mysql2 specified?

@Arcolye
Copy link

Arcolye commented Dec 2, 2015

@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.

@kimmy
Copy link

kimmy commented Dec 3, 2015

@Arcolye I was also having trouble with the versions and all, and I'm also using rails 3.2. Tried 0.3.15, and 0.3.20 but no luck. I read your comment about using 0.3.17 and it worked. Thanks!

@augus-zz
Copy link

augus-zz commented Dec 3, 2015

@kbleabres @sodabrew it's ok after I exec scripts as follows

rm -rf vendor/bundle
bundle install

@oholubyev
Copy link

@sodabrew 0.3.17 has done it, thanks!

@aashish
Copy link

aashish commented Dec 14, 2015

I am using rails 2.3.18 with mysql 0.3.17, 0.3.15. 0.3.20 on Mac Caption.
I am getting the error as follows

with mysql 0.3.15 the error is

=> Rails 2.3.18 application starting on http://0.0.0.0:8000
/Users/AChittimilla/.rvm/gems/ruby-1.9.3-p551@webstore-admin/gems/activesupport-2.3.18/lib/active_support/dependencies.rb:131:in rescue in const_missing': uninitialized constant Mysql2::Client::SECURE_CONNECTION (NameError) from /Users/AChittimilla/.rvm/gems/ruby-1.9.3-p551@webstore-admin/gems/activesupport-2.3.18/lib/active_support/dependencies.rb:120:inconst_missing'
from /Users/AChittimilla/.rvm/gems/ruby-1.9.3-p551@webstore-admin/gems/mysql2-0.3.15/lib/mysql2/client.rb:12:in `class:Client'
from /Users/AChittimilla/.rvm/gems/ruby-1.9.3-p551@webstore-admin/gems/mysql2-0.3.15/

with mysql 0.3.17 and 0.3.20 the error is

Gem::SourceIndex#search called from /Users/AChittimilla/.rvm/gems/ruby-1.9.3-p551@webstore-admin/gems/rails-2.3.18/lib/rails/vendor_gem_source_index.rb:119.
/Users/AChittimilla/.rvm/gems/ruby-1.9.3-p551@webstore-admin/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in rescue in rescue in establish_connection': Please install the mysql2 adapter:gem install activerecord-mysql2-adapter(cannot load such file -- active_record/connection_adapters/mysql2_adapter) (RuntimeError) from /Users/AChittimilla/.rvm/gems/ruby-1.9.3-p551@webstore-admin/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract/connection_specification.rb:73:inrescue in establish_connection'

@sodabrew
Copy link
Collaborator

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.

@aashish
Copy link

aashish commented Dec 14, 2015

Thanks, changing to mysql2 gem to 0.2.24 worked !!

@cheef
Copy link

cheef commented Jan 11, 2016

Upgrading to mysql 0.3.20 fix this exact error, but since mysql 5.7 adds breaking changes to primary keys I receive ActiveRecord::StatementInvalid: Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key.. error. It looks like the only way to make it work is to downgrade to mysql 5.6.

@justincase
Copy link
Contributor

@cheef

MySQL 5.7 contains incompatible changes.

Columns in a PRIMARY KEY must be NOT NULL, but if declared explicitly as NULL produced no error. Now an error occurs. For example, a statement such as CREATE TABLE t (i INT NULL PRIMARY KEY) is rejected. The same occurs for similar ALTER TABLE statements.

Checkout rails/rails#13247

On 11 jan. 2016, at 17:05, Ivan Garmatenko [email protected] wrote:

Upgrading to mysql 0.3.20 fix this exact error, but since mysql 5.7 adds breaking changes to primary keys I receive ActiveRecord::StatementInvalid: Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key.. error. It looks like the only way to make it work is to downgrade to mysql 5.6.


Reply to this email directly or view it on GitHub.

daronco added a commit to mconf/bigbluebutton_rails that referenced this issue Jul 22, 2016
Fixes "uninitialized constant Mysql2::Client::SECURE_CONNECTION".

Related to brianmario/mysql2#603
@paralaks
Copy link

paralaks commented Jan 2, 2017

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,

@sodabrew
Copy link
Collaborator

sodabrew commented Jan 2, 2017

@paralaks The workaround for this was added to mysql2 more than two years ago. No action is required unless you're using an ancient version of the gem at this point.

@paralaks
Copy link

paralaks commented Jan 2, 2017

@sodabrew I am on an old version of the gem and I can not upgrade.

@ghost
Copy link

ghost commented Jan 31, 2017

@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.

@paralaks
Copy link

@Stefanovskyi-Oleksandr As I said earlier, upgrade is not possible for my project. Anyone in a similar situation can use my workaround.

@scimax
Copy link

scimax commented Jun 4, 2017

@paralaks Thank you very much!! I have the task to upgrade a old instance of gitlab (6.4.2) and after upgrading the OS this error occurred. This helped me to get gitlab back working again.

@wellington1993
Copy link

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

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