更新到mysql 8安装后,mysql gem出现问题

时间:2018-06-24 13:23:53

标签: mysql ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2

我最近通过brew升级将MySQL更新到最新版本:

$ mysql -V
mysql  Ver 8.0.11 for osx10.13 on x86_64 (Homebrew)

现在我的Ruby on Rails mysql连接停止工作。

为了与生产环境兼容,我必须使用gem 'mysql', '2.8.1',并且在进行更新之前一切都工作正常。更新mysql后,我收到以下错误消息:

$ rails s
=> Booting WEBrick
=> Rails 3.2.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
    SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
    This poses a security threat. It is strongly recommended that you
    provide a secret to prevent exploits that may be possible from crafted
    cookies. This will not be supported in future versions of Rack, and
    future versions will even invalidate your existing user cookies.

    Called from: /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/actionpack-3.2.5/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.

Exiting
/Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/mysql_adapter.rb:32:in `mysql_connection': undefined method `init' for Mysql:Class (NoMethodError)
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in `send'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in `new_connection'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in `checkout_new_connection'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in `checkout'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `loop'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `checkout'
from /Users/MyAccount/.rvm/rubies/ruby-version/lib/ruby/1.8/monitor.rb:242:in `synchronize'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in `checkout'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `connection'
from /Users/MyAccount/.rvm/rubies/ruby-version/lib/ruby/1.8/monitor.rb:242:in `synchronize'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connection'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activerecord-3.2.5/lib/active_record/railtie.rb:97:in `_callback_before_13'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:418:in `_run__1580337521__prepare__4__callbacks'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:405:in `send'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:405:in `__run_callback'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:81:in `send'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/actionpack-3.2.5/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/actionpack-3.2.5/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/application/finisher.rb:47
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/initializable.rb:30:in `run'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/initializable.rb:55:in `run_initializers'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/initializable.rb:54:in `each'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/application.rb:136:in `initialize!'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/railtie/configurable.rb:30:in `send'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/railties-3.2.5/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/MyAccount/Development/REPRO/webapp/config/environment.rb:9
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:in `gem_original_require'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:in `require'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:in `require'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:in `require'
from /Users/MyAccount/Development/REPRO/webapp/config.ru:3
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/rack-1.4.7/lib/rack/builder.rb:51:in `instance_eval'
from /Users/MyAccount/.rvm/gems/ruby-version@webapp/gems/rack-1.4.7/lib/rack/builder.rb:51:in `initialize'
from /Users/MyAccount/Development/REPRO/webapp/config.ru:0:in `new'
from /Users/MyAccount/Development/REPRO/webapp/config.ru:0

如何解决此问题?有没有办法解决mysql连接问题?

不幸的是,mysql2不适用于生产环境。

更新mysql版本:

$ brew info mysql
mysql: stable 8.0.11 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/8.0/en/
Conflicts with:
  mariadb (because mysql, mariadb, and percona install the same binaries.)
  mariadb-connector-c (because both install plugins)
  mysql-cluster (because mysql, mariadb, and percona install the same binaries.)
  mysql-connector-c (because both install MySQL client libraries)
  percona-server (because mysql, mariadb, and percona install the same binaries.)
/usr/local/Cellar/mysql/5.7.21 (323 files, 233.9MB)
  Poured from bottle on 2018-02-21 at 14:26:22
/usr/local/Cellar/mysql/8.0.11 (254 files, 232.6MB) *
  Poured from bottle on 2018-06-22 at 06:21:48
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb
==> Dependencies
Build: cmake ✔
Required: openssl ✔
==> Requirements
Required: macOS >= 10.10 ✔
==> Options
--with-debug
    Build with debug support
--with-embedded
    Build the embedded server
--with-local-infile
    Build with local infile loading support
--with-memcached
    Build with InnoDB Memcached plugin
--with-test
    Build with unit tests
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

使用5.7.21,一切正常。

1 个答案:

答案 0 :(得分:3)

经过大量工作,我找到了罪魁祸首。 MySQL 8.0.11不够稳定,会破坏我的几个宝石。

最后,它足以:

$ brew info mysql(获取有关已安装版本的信息)

$ brew switch mysql 5.7.21(切换到稳定版本)

现在,服务器,mysql gems和数据库连接再次正常工作……

就我而言,无需卸载mysql 8。