質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails 7

Ruby on Rails 7は、2021年12月に正式リリースされました。Ruby on Railsのバージョン7であり、フロントエンド開発環境を大幅に刷新。Node.jsを用いない構成がデフォルトになっています。

Q&A

1回答

676閲覧

Rails new ○○ -d mysql でエラーがでる。 bundle installもできない。MySQLをRailsで使いたい。

takedayusukekkk

総合スコア2

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails 7

Ruby on Rails 7は、2021年12月に正式リリースされました。Ruby on Railsのバージョン7であり、フロントエンド開発環境を大幅に刷新。Node.jsを用いない構成がデフォルトになっています。

0グッド

0クリップ

投稿2022/10/23 05:21

Rails7でMysqlをデータベースに指定して、アプリを作っています。
rails new ○○○ -d mysql をコマンドプロンプトで実行したときに以下のエラーがでました。

エラー

省略ー--

[14556, #<Thread:0x000002d72be75798 run>, #<NameError: uninitialized constant Gem::Source

(defined?(@source) && @source) || Gem::Source::Installed.new ^^^^^^^^

Did you mean? Gem::SourceList>, ["C:/Ruby/Ruby31-

省略ーー

/friendly_errors.rb:103:in with_friendly_errors'", "C:/Ruby/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bundler-2.3.7/libexec/bundle:36:in <main>'"]]
C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_ext.rb:18:in `source': uninitialized constant Gem::Source (NameError)

(defined?(@source) && @source) || Gem::Source::Installed.new ^^^^^^^^

Did you mean? Gem::SourceList
from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_ext.rb:50:in `extension_dir'

省略ー--

internal:C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb:167:in `ensure in require': CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before false -> after true (RuntimeError)

省略ー---

C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_ext.rb:18:in `source': uninitialized constant Gem::Source (NameError)

(defined?(@source) && @source) || Gem::Source::Installed.new ^^^^^^^^

Did you mean? Gem::SourceList
from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_ext.rb:50:in extension_dir' from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/rubygems/basic_specification.rb:339:in have_file?'
from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/rubygems/basic_specification.rb:86:in `contains_requirable_file?'

省略ー---

run bundle binstubs bundler

Could not find gem 'mysql2 (> 0.5)' in locally installed gems.
rails importmap:install
Could not find gem 'mysql2 (
> 0.5)' in locally installed gems.
Run bundle install to install missing gems.
rails turbo:install stimulus:install
Could not find gem 'mysql2 (~> 0.5)' in locally installed gems.
Run bundle install to install missing gems.

長くなりすみません。

そのご、作成されたフォルダに移動し、bundle installを実行してみたら以下のエラーがでました。

エラー
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies.....
Using rake 13.0.6
Using racc 1.6.0
Using concurrent-ruby 1.1.10
Using minitest 5.16.3
Using builder 3.2.4
Using erubi 1.11.0
Using crass 1.0.6
Using rack 2.2.4
Using nio4r 2.5.8
Using bundler 2.3.7
Using websocket-extensions 0.1.5
Using marcel 1.0.2
Using mini_mime 1.1.2
Using timeout 0.3.0
Using public_suffix 5.0.0
Using bindex 0.8.1
Using msgpack 1.6.0
Using matrix 0.4.2
Using regexp_parser 2.6.0
Using childprocess 4.1.0
Using method_source 1.0.0
Using thor 1.2.1
Using zeitwerk 2.6.1
Using rexml 3.2.5
Using rubyzip 2.3.2
Using websocket 1.2.9
Using i18n 1.12.0
Using tzinfo 2.0.5
Using nokogiri 1.13.9 (x64-mingw-ucrt)
Using rack-test 2.0.2
Fetching mysql2 0.5.4
Using websocket-driver 0.7.5
Using mail 2.7.1
Using net-protocol 0.1.3
Using addressable 2.8.1
Using puma 5.6.5
Using sprockets 4.1.1
Using bootsnap 1.13.0
Using activesupport 7.0.4
Using loofah 2.19.0
Using xpath 3.2.0
Using selenium-webdriver 4.5.0
Using net-imap 0.3.1
Using net-pop 0.1.2
Using net-smtp 0.3.2
Using rails-dom-testing 2.0.3
Using rails-html-sanitizer 1.4.3
Using activemodel 7.0.4
Using globalid 1.0.0
Using capybara 3.37.1
Using webdrivers 5.2.0
Using actionview 7.0.4
Using activejob 7.0.4
Using activerecord 7.0.4
Using actionpack 7.0.4
Using jbuilder 2.11.5
Using actioncable 7.0.4
Using activestorage 7.0.4
Using actionmailer 7.0.4
Using railties 7.0.4
Using sprockets-rails 3.4.2
Using actionmailbox 7.0.4
Using actiontext 7.0.4
Using importmap-rails 1.1.5
Using stimulus-rails 1.1.0
Using turbo-rails 1.3.2
Using web-console 4.2.0
Using rails 7.0.4
Installing mysql2 0.5.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/Ruby/Ruby31-x64/lib/ruby/gems/3.1.0/gems/mysql2-0.5.4/ext/mysql2
C:/Ruby/Ruby31-x64/bin/ruby.exe -I C:/Ruby/Ruby31-x64/lib/ruby/3.1.0 -r
./siteconf20221023-9916-ue8zvc.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... 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:/Ruby/Ruby31-x64/bin/$(RUBY_BASE_NAME)
--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:/Ruby/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in block in find_library': undefined method split' for nil:NilClass (NoMethodError)

paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)} ^^^^^^ from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `each' from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `flat_map' from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `find_library' from extconf.rb:103:in `<main>'

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

C:/Ruby/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/mysql2-0.5.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in

省略ー--

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

In Gemfile:
mysql2

自分なりに調べたのですが、opensslのことやそのほかにもいろいろ出てきましたが全くわかりません。

自分でもopensslというものをパソコンにインストールしてみたりしたのですが、よくわかりません。
opensslというものは必要なのでしょうか。

初心者向けにはじめから説明してあるサイトなどを見つけることができなかったので、なにをどうすればいいのかわかりません。

エラー文の中にでているmkmf.logファイルも見てみたのですが、全くわかりません。

なにかファイルが足りないのでしょうか。

実現したいこと

railsアプリでmysqlをデータベースとして設定すること。

Ruby3.1.2 Rails7 os→windows

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

Installing mysql2 0.5.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

MySQL用のgemをビルドできないエラーが出ています。
おそらく、MySQL開発用のライブラリなどが無いのでは?

Unix系OS(LinuxやMacOS)では、mysql-devやlibmysqlclient.dylibなどのライブラリが必要です。

Windows用のmysqlライブラリを探してインストールしてください。

それよりもWindowsなどやめて、Linux/MacOSでの構築をお勧めします。

投稿2022/10/23 14:32

編集2022/10/23 14:34
technocore

総合スコア7200

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takedayusukekkk

2022/10/23 21:38

ありがとうございます。 アドバイスの通りでした! windowsのパソコンでの開発は良くないですか?
technocore

2022/10/24 00:57

Railsはオープンソース系で動かす前提のフレームワークなので、 LinuxやMacOSではすぐに実現できることが、Windowsではかなり苦労します。 どうしてもWindowsで開発したいのであればそれでもかまいません。
takedayusukekkk

2022/10/24 01:39

mysqlのコネクタのライブラリをrubyフォルダ内にあるlibmariadb.dllと差し替えることで解決しました。 詳しくなくてすみません。 windowsはほかのosと比べて特殊なのですか? また、その後別のエラーがでました。 ActiveRecord::ConnectionNotEstablished SSL connection error: unknown error number エラーばかりです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問