升级到mysql 8安装后mysql gem出现问题

oogrdqng  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(409)

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

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

现在我的rubyonrails 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一切正常。

c6ubokkw

c6ubokkw1#

经过大量工作,我终于找到了罪犯。MySQL8.0.11不够稳定,破坏了我的一些宝石。
最后,这足以: $ brew info mysql (获取有关已安装版本的信息) $ brew switch mysql 5.7.21 (切换到稳定版本)
现在服务器、mysql gems以及db连接又开始工作了…
在我的例子中,没有必要卸载mysql 8。

相关问题