RSpec测试-Mysql2 :: Error :: ConnectionError

时间:2018-08-15 17:34:31

标签: mysql rspec rubygems

好像我的mysql2 gem无法连接到数据库。我可以使用其他mysql客户端工具轻松连接到mysql数据库。我检查了用于RSpec的数据库连接字符串,它是正确的。运行a_spec.rb规格文件时出现以下错误。

Failure/Error: @db_client = DBClient.new
     Mysql2::Error::ConnectionError:
       SSL connection error: error:00000001:lib(0):func(0):reason(1)
     # ./vendor/cache/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `connect'
     # ./vendor/cache/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `initialize'
     # ./helpers/db_client.rb:9:in `new'
     # ./helpers/db_client.rb:9:in `initialize'
     # ./v1/agent_summary_data_spec.rb:9:in `new'
     # ./v1/agent_summary_data_spec.rb:9:in `block (3 levels) in <top (required)>'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `load'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in `run'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli.rb:424:in `exec'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli.rb:27:in `dispatch'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli.rb:18:in `start'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
     # /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'

我正在我的机器上运行以下版本的mysql

$ mysql --version
mysql  Ver 8.0.12 for osx10.12 on x86_64 (Homebrew)

我正在使用以下宝石

$ gem which mysql2
/Users/.rvm/gems/ruby-2.3.4/gems/mysql2-0.5.2/lib/mysql2.rb

有什么想法吗?想知道是否有人遇到过类似的问题。 谢谢!

1 个答案:

答案 0 :(得分:0)

最后,我能够解决以上SSL问题。使用以下命令卸载并重新安装了mysql2 gem。它做到了魔术。

bundle exec gem uninstall mysql2

bundle install