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

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

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

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

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

1973閲覧

rails db:createに対するエラー文に関して、、ご教授お願いします!

suirunakamura

総合スコア16

MySQL

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

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/07/26 07:04

下記コードは、rails db:createコマンドをターミナル上に実行した際の記述です。

rooter:portfolio apple$ rails db:create rails aborted! LoadError: dlopen(/Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 0x0009): dependent dylib '/usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib' not found for '/Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle' - /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `block in require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2.rb:36:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `block (2 levels) in require' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `each' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `block in require' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `each' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `require' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler.rb:174:in `require' /Users/apple/create/portfolio/config/application.rb:7:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `block in require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:49:in `require_relative' /Users/apple/create/portfolio/Rakefile:4:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:318:in `block in load' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:318:in `load' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:22:in `block in perform' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/command.rb:48:in `invoke' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands.rb:18:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `block in require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require' /Users/apple/create/portfolio/bin/rails:9:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>' /Users/apple/create/portfolio/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' (See full trace by running task with --trace)

この文をみていると、依存関係の内容が表示されていたので今回作成しているアプリケーションのgem内でのMYsqlのバージョンとLinuxコマンドで設定した全体のMYsqlのバージョンが違うのも原因なのかなと思います。
今回の作成しているMysqlのバージョンはgem 'mysql2'を設定していて、Linuxコマンドでは、mysqlを使用しています。

また、パスの設定が原因もあるのかなと、、前に自分で任意のパスの設定をして しまっていて、下記の表示にあるMysql5.7は設定してないので、、

rooter:portfolio apple$ echo $PATH /usr/local/opt/mysql@8.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/mysql@8.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/mysql@8.0/bin:/usr/local/opt/mysql@5.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

ご教授お願いします、、

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

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

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

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

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

guest

回答1

0

ベストアンサー

この場合は一番最初に書かれていますね
'/usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib' not found
mysql2を動かすのに必要な dylibがないというエラーです。
mysql2はgemなので、mysqlとはversion表記が違うのは構わないのですが、mysql2を gem install したときと mysqlのversionを変えたりしていますか?

OS他環境を書いておくともっと適切な人の助言が得られると思います。
Linuxとありますが、Linuxのdir名ではないので、、、、Macですか?

投稿2020/07/26 07:12

winterboum

総合スコア23329

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

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

suirunakamura

2020/07/26 07:30

winterboumさん!返信ありがとうございます!Macを使用しています。MacOS catalinaのバージョン10.15.4(19E287)を使用しています。 gemは、最初デフォルトでsqliteが設定されていて、mysqlに変更しました。過去にエラー文が重なったためgemでもLinuxの方でも、mysqlのバージョンはたくさん変更してしまいました。
winterboum

2020/07/26 08:26

libmysqlclient.20.dylib のversionの合うmysqlを入れなおすか、 今の mysqlにあう mysql2に作りなおすか。ですが後者の方がよいかな。。。 やったことがないのですが、以下の手順を試してください 1. gem uninstall mysql2 する 2. bundle install する
suirunakamura

2020/07/26 08:35

返信ありがとうございます!かしこまりました!
suirunakamura

2020/07/26 08:40 編集

gem uninstall mysql2コマンド rooter:portfolio apple$ gem uninstall mysql2 ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory. rooter:portfolio apple$ sudo gem uninstall mysql2 Password: Sorry, try again. Password: Successfully uninstalled mysql2-0.5.3 bundle installコマンド rooter:portfolio apple$ bundle install The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. Fetching gem metadata from https://rubygems.org/............ Using rake 13.0.1 Following files may not be writable, so sudo is needed: /Library/Ruby/Gems/2.6.0 /Library/Ruby/Gems/2.6.0/build_info /Library/Ruby/Gems/2.6.0/build_info/mysql2-0.5.3.info /Library/Ruby/Gems/2.6.0/cache /Library/Ruby/Gems/2.6.0/doc /Library/Ruby/Gems/2.6.0/extensions /Library/Ruby/Gems/2.6.0/gems /Library/Ruby/Gems/2.6.0/specifications Using concurrent-ruby 1.1.6 Using i18n 1.8.3 Using minitest 5.14.1 Using thread_safe 0.3.6 Using tzinfo 1.2.7 Using zeitwerk 2.3.0 Using activesupport 6.0.3.1 Using builder 3.2.4 Using erubi 1.9.0 Using mini_portile2 2.4.0 Using nokogiri 1.10.9 Using rails-dom-testing 2.0.3 Using crass 1.0.6 Using loofah 2.5.0 Using rails-html-sanitizer 1.3.0 Using actionview 6.0.3.1 Using rack 2.2.2 Using rack-test 1.1.0 Using actionpack 6.0.3.1 Using nio4r 2.5.2 Using websocket-extensions 0.1.5 Using websocket-driver 0.7.2 Using actioncable 6.0.3.1 Using globalid 0.4.2 Using activejob 6.0.3.1 Using activemodel 6.0.3.1 Using activerecord 6.0.3.1 Using mimemagic 0.3.5 Using marcel 0.3.3 Using activestorage 6.0.3.1 Using mini_mime 1.0.2 Using mail 2.7.1 Using actionmailbox 6.0.3.1 Using actionmailer 6.0.3.1 Using actiontext 6.0.3.1 Using active_hash 3.1.0 Using public_suffix 4.0.5 Using addressable 2.7.0 Using ancestry 3.0.7 Using bcrypt 3.1.13 Using bindex 0.8.1 Using msgpack 1.3.3 Using bootsnap 1.4.6 Using bundler 2.1.4 Using byebug 11.1.3 Using regexp_parser 1.7.1 Using xpath 3.2.0 Using capybara 3.32.2 Using mini_magick 4.10.1 Using ffi 1.13.0 Using ruby-vips 2.0.17 Using image_processing 1.11.0 Using carrierwave 2.1.0 Using childprocess 3.0.0 Using coderay 1.1.3 Using orm_adapter 0.5.0 Using method_source 1.0.0 Using thor 1.0.1 Using railties 6.0.3.1 Using responders 3.0.1 Using warden 1.2.8 Using devise 4.7.1 Using unf_ext 0.0.7.7 Using unf 0.1.4 Using domain_name 0.5.20190701 Using dotenv 2.7.5 Using dotenv-rails 2.7.5 Using dynamic_form 1.1.4 Using erubis 2.7.0 Using temple 0.8.2 Using tilt 2.0.10 Using haml 5.1.2 Using sexp_processor 4.14.1 Using ruby_parser 3.14.2 Using html2haml 2.2.0 Using erb2haml 0.1.5 Using excon 0.73.0 Using formatador 0.2.5 Using mime-types-data 3.2020.0512 Using mime-types 3.3.1 Using fog-core 2.2.0 Using multi_json 1.14.1 Using fog-json 1.2.0 Using fog-xml 0.1.3 Using ipaddress 0.8.3 Using fog-aws 3.6.5 Using sassc 2.4.0 Using font-awesome-sass 5.13.0 Using sprockets 4.0.2 Using sprockets-rails 3.2.1 Using rails 6.0.3.1 Using gretel 3.0.9 Using haml-rails 2.0.1 Using http-accept 1.7.0 Using http-cookie 1.0.3 Using jbuilder 2.10.0 Using jquery-rails 4.4.0 Using turbolinks-source 5.2.0 Using turbolinks 5.2.1 Using jquery-turbolinks 2.1.0 Using rb-fsevent 0.10.4 Using rb-inotify 0.10.1 Using ruby_dep 1.5.0 Using listen 3.1.5 Fetching mysql2 0.5.3 Your user account isn't allowed to install to the system RubyGems. You can cancel this installation and run: bundle install --path vendor/bundle to install the gems into ./vendor/bundle/, or you can enter your password and install the bundled gems to RubyGems using sudo. Password: Installing mysql2 0.5.3 with native extensions Using netrc 0.11.0 Using rest-client 2.1.0 Using payjp 0.0.7 Using pry 0.13.1 Using pry-rails 0.3.9 Using puma 4.3.5 Using rubyzip 2.3.0 Using sassc-rails 2.1.2 Using sass-rails 6.0.0 Using selenium-webdriver 3.142.7 Using spring 2.1.0 Using spring-watcher-listen 2.0.1 Using web-console 4.0.2 Using webdrivers 4.4.1 Bundle complete! 32 Gemfile dependencies, 120 gems now installed. Gems in the groups production and prosuction were not installed. Use `bundle info [gemname]` to see where a bundled gem is installed.
suirunakamura

2020/07/26 08:40

おそらく、gemfile にmysql2の記述が入っているので、bundle install でmysql2が再インストールされました。このコマンドでよろしいですか?
winterboum

2020/07/26 08:41

これで db:create するとどうなります?
suirunakamura

2020/07/27 07:07 編集

返信遅れすみません!rails db:createコマンドを実行しました。エラー文が変わったようです。 エラー文が長く、全てペーストしてきて申し訳ありいません。これは、データベース名が重複しているエラーです。これに関しては、アプリケーションのコンソールを使用してcreateできなかったのでmysqlで、別個のアプリとは、リンクされていないデータベースを作成していました。このデータベースを削除して再度createコマンド実行を試す必要がありますか? rooter:portfolio apple$ rails db:create Database 'portfolio_development' already exists Mysql2::Error: Incorrect database name '' Couldn't create '' database. Please check your configuration. rails aborted! ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect database name '' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:201:in `block (2 levels) in execute' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:200:in `block in execute' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:722:in `block (2 levels) in log' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:721:in `block in log' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:712:in `log' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:199:in `execute' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/mysql/database_statements.rb:41:in `execute' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:256:in `create_database' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:126:in `create' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:185:in `block in create_current' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:479:in `block (2 levels) in each_current_configuration' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:476:in `each' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:476:in `block in each_current_configuration' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:475:in `each' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:475:in `each_current_configuration' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:184:in `create_current' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:39:in `block (2 levels) in <main>' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/command.rb:48:in `invoke' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands.rb:18:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `block in require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require' /Users/apple/create/portfolio/bin/rails:9:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>' /Users/apple/create/portfolio/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>'
suirunakamura

2020/07/27 07:00

Caused by: Mysql2::Error: Incorrect database name '' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:201:in `block (2 levels) in execute' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:200:in `block in execute' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:722:in `block (2 levels) in log' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:721:in `block in log' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:712:in `log' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:199:in `execute' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/mysql/database_statements.rb:41:in `execute' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:256:in `create_database' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:126:in `create' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:185:in `block in create_current' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:479:in `block (2 levels) in each_current_configuration' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:476:in `each' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:476:in `block in each_current_configuration' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:475:in `each' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:475:in `each_current_configuration' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:184:in `create_current' /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:39:in `block (2 levels) in <main>' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/command.rb:48:in `invoke' /Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands.rb:18:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `block in require' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require' /Users/apple/create/portfolio/bin/rails:9:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>' /Users/apple/create/portfolio/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Tasks: TOP => db:create (See full trace by running task with --trace)
winterboum

2020/07/27 07:29

このデータベースを削除して再度createコマンド実行  してください
suirunakamura

2020/07/27 07:48

mysqlにログインし、データベースを削除しcreateコマンドを実行した結果、先ほどと同じエラーが発生してしまいました。再度mysqlにログインしてみると、先ほど削除したはずのデータベースが存在していました。dropコマンドの後に、変更点の保存などの動作をしないとデータベースの削除が反映されないということでしょうか? すみません、ご助言があればいただきたいです! mysql> SHOW DATABASES; +-----------------------+ | Database | +-----------------------+ | information_schema | | mysql | | performance_schema | | portfolio_development | | sys | +-----------------------+ 5 rows in set (0.03 sec) mysql> drop database portfolio_development; Query OK, 0 rows affected (0.01 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> exit Bye rooter:portfolio apple$ rails db:create Created database 'portfolio_development' Mysql2::Error: Incorrect database name '' Couldn't create '' database. Please check your configuration. rails aborted! ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect database name '' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query'
suirunakamura

2020/07/27 07:49

下記のコマンドがcreateコマンド後の実行コードです。 rooter:portfolio apple$ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 32 Server version: 8.0.19 Homebrew Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SHOW DATABASES; +-----------------------+ | Database | +-----------------------+ | information_schema | | mysql | | performance_schema | | portfolio_development | | sys | +-----------------------+ 5 rows in set (0.03 sec)
winterboum

2020/07/27 07:55

様子は変わってますね Database 'portfolio_development' already exists が無くなってる。 ですが、incorrectですか。 逃げの手を打ちましょう。 config/database.yml にある database: portfolio_developmentのところを別の名前に、例えば portfolio_develop  にして db:create
suirunakamura

2020/07/27 08:28

度々、愚問申し訳ありません。データベース名の変更を試みた結果、どうもうまくいきませんでした。renameコマンドの使用方法を間違っていますか?ご教授もらえれば幸いです。 mysql> rename portfolio_development to portfolio_develop -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'portfolio_development to portfolio_develop' at line 1 mysql> rename portfolio_development to portfolio_develop; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'portfolio_development to portfolio_develop' at line 1 mysql> RENAME portfolio_development to portfolio_develop -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'portfolio_development to portfolio_develop' at line 1 mysql> RENAME portfolio_development to portfolio_develop; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'portfolio_development to portfolio_develop' at line 1 mysql> ALTER TABLE portfolio_development RENAME portfolio_dev; ERROR 1046 (3D000): No database selected mysql> ALTER TABLE portfolio_development RENAME portfolio_dev; ERROR 1046 (3D000): No database selected mysql> RENAME TABLE portfolio_development TO portfolio_dev; ERROR 1046 (3D000): No database selected
winterboum

2020/07/27 09:21

いえ、mysqlでの操作はとりあえずわすれてください。 Railsが使うDB名を変えます。
suirunakamura

2020/07/27 09:26

理解が遅く申し訳ありません。今回作成するDBの名前を少し変えるということですね! やってみます!
suirunakamura

2020/07/28 08:22

データベース作成ができました!ありがとうございます! 本当に愚問で申し訳ありませんでした。 rooter:portfolio apple$ rails db:create Created database 'portfolio1_development' Created database 'portfolio1_test' rooter:portfolio apple$
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問