运行 rake 任务时 nil:NilClass 的未定义方法 "accept"

Undefined method "accept" for nil:NilClass when running rake tasks

我有一个 Ruby-on-Rails (3.2.2) 应用程序 mysql2 (0.5.1) 和 MyQSL 服务器

mysql --version

mysql --version x86_64(自制软件)上的 osx10.13 版本 8.0.11。

当我执行 bundle exec rake db:setup 时,数据库被创建。

当我尝试 bundle exec rake db:migrate 时出现此故障:

bundle exec rake db:migrate --trace                                                                           
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
NoMethodError: undefined method `accept' for nil:NilClass
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/database_statements.rb:38:in `select_values'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:587:in `get_all_versions'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:745:in `migrated'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:668:in `current_version'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:685:in `block in migrate'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:685:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:685:in `detect'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:685:in `migrate'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:570:in `up'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:551:in `migrate'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:424:in `exec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:27:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:18:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `<main>'
Tasks: TOP => db:migrate

我没有找到任何解决方案。 我必须安装 gem "activerecord-mysql2-adapter" 才能 运行 它。 没有那个 gem 它会抛出这个:

LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.5.1. Make sure all dependencies are added to Gemfile.)

当我 运行 我的旧版本(mysql2 0.3.2.1 的原始版本)发生了这种情况: (因为这次失败我做了更新)

gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'                                                5 ↵  2.3.3    RSpec: 128.09%
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/ext/mysql2
/Users/janjezek/.rbenv/versions/2.3.3/bin/ruby -r ./siteconf20180629-41801-6cf56s.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting rpath to /usr/local/Cellar/mysql/8.0.11/lib
-----
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:



    /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-17/2.3.0-static/mysql2-0.3.21/mkmf.log

    current directory: /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/ext/mysql2
    make "DESTDIR=" clean

    current directory: /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/ext/mysql2
    make "DESTDIR="
    compiling infile.c
    compiling client.c
    client.c:439:3: error: use of undeclared identifier 'my_bool'
      my_bool res = mysql_read_query_result(client);
      ^
    client.c:441:19: error: use of undeclared identifier 'res'
      return (void *)(res == 0 ? Qtrue : Qfalse);
                      ^
    client.c:762:3: error: use of undeclared identifier 'my_bool'
      my_bool boolval;
      ^
    client.c:793:7: error: use of undeclared identifier 'boolval'
          boolval = (value == Qfalse ? 0 : 1);
          ^
    client.c:794:17: error: use of undeclared identifier 'boolval'
          retval = &boolval;
                    ^
    client.c:797:10: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
        case MYSQL_SECURE_AUTH:
             ^~~~~~~~~~~~~~~~~
             MYSQL_DEFAULT_AUTH
    /usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
      MYSQL_DEFAULT_AUTH,
      ^
    client.c:798:7: error: use of undeclared identifier 'boolval'
          boolval = (value == Qfalse ? 0 : 1);
          ^
    client.c:799:17: error: use of undeclared identifier 'boolval'
          retval = &boolval;
                    ^
    client.c:830:38: error: use of undeclared identifier 'boolval'
            wrapper->reconnect_enabled = boolval;
                                         ^
    client.c:1185:38: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
      return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
                                         ^~~~~~~~~~~~~~~~~
                                         MYSQL_DEFAULT_AUTH
    /usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
      MYSQL_DEFAULT_AUTH,
      ^
    10 errors generated.
    make: *** [client.o] Error 1

    make failed, exit code 2

    Gem files will remain installed in /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21 for inspection.
    Results logged to /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-17/2.3.0-static/mysql2-0.3.21/gem_make.out

(顺便说一句:我可以连接到 mysql -u root -p,并且创建的数据库在那里。)

还有什么建议吗?

完成:

database.yml

development:
  adapter: mysql2
  host: 127.0.0.1
  port: 3306
  database: mydb_development
  username: root
  password: root

编辑:

没有 mysqladapter gem:

rake aborted!
LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.10. Make sure all dependencies are added to Gemfile.)
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `block in require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:29:in `spec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:101:in `create_database'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:424:in `exec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:27:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:18:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `<main>'
Gem::LoadError: can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.10. Make sure all dependencies are added to Gemfile.
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `block in require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:29:in `spec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:101:in `create_database'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:424:in `exec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:27:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:18:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `<main>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create

尝试摆脱 gem activerecord-mysql2-adapter 并只安装 gem mysql2 它应该可以工作

您需要安装 mysql2 gem 或任何替代软件。带有本机扩展 的 Gem 有时需要 development 它们所绑定的库的库进行编译。也就是说:

# gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'
Building native extensions.  This could take a while...
  ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

—表示您需要安装 libmysqlclient-dev 包(Ubuntu,在其他 OS 上请阅读相应的文档。)

要在 Ubuntu、运行 sudo apt-get install libmysqlclient-dev.

上安装此软件包

TL;DR;

这是 Ruby 的 Rails 3.2.22

我的 mac 上有 mysql 版本 8.x。 我也安装了 5.6。 我发现该应用程序的原始 mysql 服务器是 5.7.

所以我安装了 mysql Version 5.7 并且成功了!

清理中

宝石文件:

gem 'mysql2', '~> 0.3.21' # in Gemfile


brew uninstall mysql mysql@5.6
brew install mysql@5.7

清理 /Users/YOURNAME/.rbenv/versions/2.3.3/lib/ruby/gems 文件夹中的所有 mysqlactiverecord-mysql2-adapter 内容。

gem uninstall activerecord-mysql2-adapter # each version
gem uninstall mysql2 # each version
bundle update mysql2
bundle install

就是这样。谢谢大家指导我