尝试使用 mysql 数据库启动 Rails 项目时出现 Mysql 错误

Mysql Errors when trying to start Rails project with mysql database

提问人:auto 提问时间:10/23/2023 更新时间:10/23/2023 访问量:50

问:

我正在尝试在 Windows 系统上创建一个新的 Ruby Rails 项目

我已经安装了 Rails v 7.1.1

然后我跑rails new myRailsProject -d mysql

但是,会发生错误:

An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue.

In Gemfile:
  mysql2
         run  bundle lock --add-platform=x86_64-linux
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Writing lockfile to C:/Users/Me/RailsProjects/myRailsProject/Gemfile.lock
         run  bundle binstubs bundler
Could not find mysql2-0.5.5 in locally installed gems
       rails  importmap:install
Could not find mysql2-0.5.5 in locally installed gems
Run `bundle install` to install missing gems.
       rails  turbo:install stimulus:install
Could not find mysql2-0.5.5 in locally installed gems
Run `bundle install` to install missing gems.

然后我尝试按照在线论坛运行Bundle install

我得到:Could not locate Gemfile

rails 目录已经创建好了,所以我使用 cd 进入它,然后再次运行。我仍然收到一个错误:cd myRailsProjectbundle install

Fetching gem metadata from https://rubygems.org/.........
Installing mysql2 0.5.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/mysql2-0.5.5/ext/mysql2
C:/Ruby32-x64/bin/ruby.exe extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby32-x64/bin/$(RUBY_BASE_NAME)
        --with-openssl-dir
        --without-openssl-dir
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysql-config
        --without-mysql-config
        --with-mysqlclient-dir
        --without-mysqlclient-dir
        --with-mysqlclient-include
        --without-mysqlclient-include=${mysqlclient-dir}/include
        --with-mysqlclient-lib
        --without-mysqlclient-lib=${mysqlclient-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
C:/Ruby32-x64/lib/ruby/3.2.0/mkmf.rb:1083:in `block in find_library': undefined
method `split' for nil:NilClass (NoMethodError)

    paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)}
                                       ^^^^^^
        from C:/Ruby32-x64/lib/ruby/3.2.0/mkmf.rb:1083:in `each'
        from C:/Ruby32-x64/lib/ruby/3.2.0/mkmf.rb:1083:in `flat_map'
        from C:/Ruby32-x64/lib/ruby/3.2.0/mkmf.rb:1083:in `find_library'
        from extconf.rb:131:in `<main>'

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

C:/Ruby32-x64/lib/ruby/gems/3.2.0/extensions/x64-mingw-ucrt/3.2.0/mysql2-0.5.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/mysql2-0.5.5 for inspection.
Results logged to
C:/Ruby32-x64/lib/ruby/gems/3.2.0/extensions/x64-mingw-ucrt/3.2.0/mysql2-0.5.5/gem_make.out

  C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:120:in `run'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:28:in
`build'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:188:in
`build_extension'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:222:in `block
in build_extensions'
  C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:219:in `each'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:219:in
`build_extensions'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/installer.rb:844:in
`build_extensions'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/rubygems_gem_installer.rb:72:in
`build_extensions'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/rubygems_gem_installer.rb:28:in
`install'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/source/rubygems.rb:203:in
`install'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/installer/gem_installer.rb:54:in
`install'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/installer/parallel_installer.rb:130:in
`do_install'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/installer/parallel_installer.rb:121:in
`block in worker_pool'
  C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:62:in `apply_func'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:57:in `block in
process_queue'
  C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:54:in `loop'
  C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:54:in `process_queue'
C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:90:in `block (2
levels) in create_threads'

An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue.

In Gemfile:
  mysql2

我不确定出了什么问题。我的项目的 Rails 目录已创建,尽管该项目似乎没有使用 mysql,而且我无法运行 .bundle install

Ruby-on-Rails Windows RubyGems mysql2

评论

0赞 dmrlps 10/23/2023
在 Rails 项目中运行 bundle install 时遇到的错误表明无法安装 mysql2 gem,因为未安装或未在系统上运行必要的 MySQL 库或服务器。尝试在本地计算机中安装并运行 MySQL。
0赞 auto 10/24/2023
谢谢,但我安装了MySQL。我跑了,得到了.我还尝试在mysql运行的情况下运行。mysql --versionmysql Ver 8.0.34 for Win64 on x86_64 (MySQL Community Server - GPL)bundle install
0赞 auto 10/24/2023
经过长时间的搜索,我在这里找到了解决方案:stackoverflow.com/questions/19014117/......必须下载 mysql-connector 的存档版本。不知道它为什么或如何工作,但它有效。

答: 暂无答案