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

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

新規登録して質問してみよう
ただいま回答率
85.46%
docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Ruby

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

Ruby on Rails

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

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

1435閲覧

docker-compose run web rails db:create でDBを作成するとPlugin caching_sha2_password could not be loadedがでる。

madaratyou

総合スコア7

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Ruby

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

Ruby on Rails

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

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2021/04/04 12:54

前提・実現したいこと

https://www.youtube.com/watch?v=ltDdZAJli8c&t=3s コチラの動画を参考に、 docker-compose run web rails db:create というコマンドを実行し、DBを作成しようとしたところ下記の様なエラーが発生してしまいます。

コチラを解決し、DBを作成したいです。

発生している問題・エラーメッセージ

Creating rails_docker_web_run ... done Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory Couldn't create 'app_production' database. Please check your configuration. rails aborted! ActiveRecord::ConnectionNotEstablished: Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory Caused by: Mysql2::Error::ConnectionError: Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory Tasks: TOP => db:create (See full trace by running task with --trace) ERROR: 1

該当のソースコード

docker-compose.yml

YAML

1version: '3' 2services: 3 db: 4 image: mysql:8.0 5 command: --default-authentication-plugin=mysql_native_password 6 volumes: 7 - ./src/db/mysql_data:/var/lib/mysql 8 environment: 9 MYSQL_ROOT_PASSWORD: password 10 web: 11 build: . 12 command: bundle exec rails s -p 3000 -b '0.0.0.0' 13 volumes: 14 - ./src:/app 15 ports: 16 - "3000:3000" 17 depends_on: 18 - db 19

YAML

1# MySQL. Versions 5.5.8 and up are supported. 2# 3# Install the MySQL driver 4# gem install mysql2 5# 6# Ensure the MySQL gem is defined in your Gemfile 7# gem 'mysql2' 8# 9# And be sure to use new-style password hashing: 10# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html 11# 12default: &default 13 adapter: mysql2 14 encoding: utf8mb4 15 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 16 username: root 17 password: password 18 host: db 19 20development: 21 <<: *default 22 database: app_development 23 24# Warning: The database defined as "test" will be erased and 25# re-generated from your development database when you run "rake". 26# Do not set this db to the same as development or production. 27test: 28 <<: *default 29 database: app_test 30 31# As with config/credentials.yml, you never want to store sensitive information, 32# like your database password, in your source code. If your source code is 33# ever seen by anyone, they now have access to your database. 34# 35# Instead, provide the password or a full connection URL as an environment 36# variable when you boot the app. For example: 37# 38# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" 39# 40# If the connection URL is provided in the special DATABASE_URL environment 41# variable, Rails will automatically merge its configuration values on top of 42# the values provided in this file. Alternatively, you can specify a connection 43# URL environment variable explicitly: 44# 45# production: 46# url: <%= ENV['MY_APP_DATABASE_URL'] %> 47# 48# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 49# for a full overview on how database connection configuration can be specified. 50# 51production: 52 <<: *default 53 database: app_production 54 username: app 55 password: <%= ENV['APP_DATABASE_PASSWORD'] %>

試したこと

https://qiita.com/tomo-IR/items/224d33f14561e759dd16
↑野記事を参考にdocker内のmysqlにログインし、プラグインの状況を確認してみたのですが、

bash

1mysql> SELECT user, host, plugin FROM mysql.user; 2+------------------+-----------+-----------------------+ 3| user | host | plugin | 4+------------------+-----------+-----------------------+ 5| root | % | mysql_native_password | 6| mysql.infoschema | localhost | caching_sha2_password | 7| mysql.session | localhost | caching_sha2_password | 8| mysql.sys | localhost | caching_sha2_password | 9| root | localhost | mysql_native_password | 10+------------------+-----------+-----------------------+

rootユーザーのpluginは、mysql_native_password になっているため、どこが原因なのかわからなくなってしまいました。

補足情報(FW/ツールのバージョンなど)

mysql v8.0
ruby v2.7.2

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

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

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

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

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

guest

回答1

0

ベストアンサー

おそらく、データベースへの接続はユーザー: root ではなく app で行われています

console

1Couldn't create 'app_production' database. Please check your configuration.

上記のエラーが表示されるということは、
RAILS_ENVproduction に設定されているような状態になっています

注: 動画では app_production ではなく、app_development, app_test が作成されていることに注意します

RAILS_ENV については、やや長いですが、次の記事が参考になるでしょう:
ruby on railsでrake db:createをする時の挙動の詳細を教えて下さい。なぜ勝手にdevやtestのdbが作成されるのでしょうか? - Quora

RAILS_ENVproduction に設定されているような状態であるということは、
database.yml の設定も production のものが読み込まれているものと思われます:

yaml

1production: 2 <<: *default 3 database: app_production 4 username: app 5 password: <%= ENV['APP_DATABASE_PASSWORD'] %>

どこかで RAILS_ENV を設定したり、production を使うような設定をしなかったかを確認しましょう

投稿2021/04/07 17:30

y_shinoda

総合スコア3272

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

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

madaratyou

2021/04/11 03:58

Dockerfile内にそのような記述がされていました。!!ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問