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

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

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

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

MySQL

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

MariaDB

MariaDBは、MySQL派生のオープンソースなリレーショナルデータベースシステムです。 また、MySQLとほぼ同じデータベースエンジンに対応しています。

VPS

VPS(バーチャル・プライベート・サーバ)は、仮想化されたサーバをレンタルするサービスで、共有サーバでありながら専門サーバと同等の機能を果たします。物理的な専門サーバより安価で提供できるメリットがあります。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

解決済

1回答

1247閲覧

デプロイ実行でデータベースがないというエラーの解決方法を教えていただけないでしょうか?

koume

総合スコア458

Ruby on Rails 5

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

MySQL

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

MariaDB

MariaDBは、MySQL派生のオープンソースなリレーショナルデータベースシステムです。 また、MySQLとほぼ同じデータベースエンジンに対応しています。

VPS

VPS(バーチャル・プライベート・サーバ)は、仮想化されたサーバをレンタルするサービスで、共有サーバでありながら専門サーバと同等の機能を果たします。物理的な専門サーバより安価で提供できるメリットがあります。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2019/04/18 14:53

編集2019/04/18 14:54

Capistrano3でデプロイしていますがデーターベスがありません。というエラーが解決できずに困っています。
エラーの内容は以下になります。

rake aborted! ActiveRecord::NoDatabaseError: Unknown database 'panda_production' /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/activerecord-5.1.7/lib/active_record/connection_adapters/mysql2_adapter.rb:25:in `rescue in mysql2_connection' Caused by: Mysql2::Error: Unknown database 'panda_production' /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:89:in `connect' Caused by: SSHKit::Runner::ExecuteError: Exception while executing as panda@155.XXX.137.81: rake exit status: 1 rake stdout: rake aborted! ActiveRecord::NoDatabaseError: Unknown database 'panda_production' /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/activerecord-5.1.7/lib/active_record/connection_adapters/mysql2_adapter.rb:25:in `rescue in mysql2_connection'

このようにデーターベースがありません。みたいなエラーが出ています。
データベースを作成しました。

仮想マシン側 $ rails db:create RAILS_ENV=production Database 'panda_production' already exists すでに出来ていました。
VPS側 (何が出力されているかさっぱりわかりませんでした。) $ rails db:create RAILS_ENV=production Usage: rails new APP_PATH [options] Options: -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: /home/kinoko/.rbenv/versions/2.3.1/bin/ruby -m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) # Default: sqlite3 [--skip-yarn], [--no-skip-yarn] # Don't use Yarn for managing JavaScript dependencies [--skip-gemfile], [--no-skip-gemfile] # Don't create a Gemfile -G, [--skip-git], [--no-skip-git] # Skip .gitignore file [--skip-keeps], [--no-skip-keeps] # Skip source control .keep files -M, [--skip-action-mailer], [--no-skip-action-mailer] # Skip Action Mailer files -O, [--skip-active-record], [--no-skip-active-record] # Skip Active Record files -P, [--skip-puma], [--no-skip-puma] # Skip Puma related files -C, [--skip-action-cable], [--no-skip-action-cable] # Skip Action Cable files -S, [--skip-sprockets], [--no-skip-sprockets] # Skip Sprockets files [--skip-spring], [--no-skip-spring] # Don't install Spring application preloader [--skip-listen], [--no-skip-listen] # Don't generate configuration that depends on the listen gem [--skip-coffee], [--no-skip-coffee] # Don't use CoffeeScript -J, [--skip-javascript], [--no-skip-javascript] # Skip JavaScript files [--skip-turbolinks], [--no-skip-turbolinks] # Skip turbolinks gem -T, [--skip-test], [--no-skip-test] # Skip test files [--skip-system-test], [--no-skip-system-test] # Skip system test files [--dev], [--no-dev] # Setup the application with Gemfile pointing to your Rails checkout [--edge], [--no-edge] # Setup the application with Gemfile pointing to Rails repository [--rc=RC] # Path to file containing extra configuration options for rails command [--no-rc], [--no-no-rc] # Skip loading of extra configuration options from .railsrc file [--api], [--no-api] # Preconfigure smaller stack for API only apps -B, [--skip-bundle], [--no-skip-bundle] # Don't run bundle install [--webpack=WEBPACK] # Preconfigure for app-like JavaScript with Webpack (options: react/vue/angular) Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist Rails options: -h, [--help], [--no-help] # Show this help message and quit -v, [--version], [--no-version] # Show Rails version number and quit Description: The 'rails new' command creates a new Rails application with a default directory structure and configuration at the path you specify. You can specify extra command-line arguments to be used every time 'rails new' runs in the .railsrc configuration file in your home directory. Note that the arguments specified in the .railsrc file don't affect the defaults values shown above in this help message. Example: rails new ~/Code/Ruby/weblog This generates a skeletal Rails installation in ~/Code/Ruby/weblog.

とりあえずこの状態で
$ budle exec cap production deploy を実行しても同じエラーでした。

これが原因なのでしょうか?

仮想マシン側 MySQL mysql Ver 14.14 Distrib 5.6.40, for Linux (x86_64) using EditLine wrapper VPS側  MariaDB mysql Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1

MySQLとMariaDBは互換性があるみたいでしたので大丈夫だと思っています。

ただ、データベースがありませんというエラーと関連性があるのかわかりませんが、VPS側にデータベースが作成出来ないのにはなにか原因があるのでしょうか?
database.ymlはどちらの環境にも同じ設定がしてあります。

database.yml default: &default adapter: mysql2 encoding: utf8 collation: utf8_general_ci pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: XXXXX password: XXXXXXXX socket: /var/lib/mysql/mysql.sock development: <<: *default database: XXXXXXX est: <<: *default database: XXXXXXX production: <<: *default database: panda_production username: XXXXXX password: XXXXXX

エラーがでているであろうファイルをは下記になります。

/usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/activerecord-5.1.7/lib/active_record/connection_adapters/mysql2_adapter.rb require "active_record/connection_adapters/abstract_mysql_adapter" require "active_record/connection_adapters/mysql/database_statements" gem "mysql2", ">= 0.3.18", "< 0.6.0" require "mysql2" raise "mysql2 0.4.3 is not supported. Please upgrade to 0.4.4+" if Mysql2::VERSION == "0.4.3" module ActiveRecord module ConnectionHandling # :nodoc: # Establishes a connection to the database that's used by all Active Record objects. def mysql2_connection(config) config = config.symbolize_keys config[:flags] ||= 0 if config[:flags].kind_of? Array config[:flags].push "FOUND_ROWS".freeze else config[:flags] |= Mysql2::Client::FOUND_ROWS end client = Mysql2::Client.new(config) ConnectionAdapters::Mysql2Adapter.new(client, logger, nil, config) rescue Mysql2::Error => error if error.message.include?("Unknown database") raise ActiveRecord::NoDatabaseError else raise end end end module ConnectionAdapters class Mysql2Adapter < AbstractMysqlAdapter ADAPTER_NAME = "Mysql2".freeze include MySQL::DatabaseStatements def initialize(connection, logger, connection_options, config) super @prepared_statements = false unless config.key?(:prepared_statements) configure_connection end def supports_json? !mariadb? && version >= "5.7.8" end def supports_comments? true end def supports_comments_in_create? true end def supports_savepoints? true end # HELPER METHODS =========================================== def each_hash(result) # :nodoc: if block_given? result.each(as: :hash, symbolize_keys: true) do |row| yield row end else to_enum(:each_hash, result) end end def error_number(exception) exception.error_number if exception.respond_to?(:error_number) end #-- # QUOTING ================================================== #++ def quote_string(string) @connection.escape(string) end    #-- # CONNECTION MANAGEMENT ==================================== #++ def active? @connection.ping end def reconnect! super disconnect! connect end alias :reset! :reconnect! # Disconnects from the database if already connected. # Otherwise, this method does nothing. def disconnect! super @connection.close end private def connect @connection = Mysql2::Client.new(@config) configure_connection end def configure_connection @connection.query_options.merge!(as: :array) super end def full_version @full_version ||= @connection.server_info[:version] end end end end

どなたかご教示お願いします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

rails db:create RAILS_ENV=production で実行している railsbin/rails ではないように見えます。
bin/rails db:create RAILS_ENV=production としてみてください。

投稿2019/04/18 15:21

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

koume

2019/04/19 01:13

回答ありがとうございます。 bin/rails db:create RAILS_ENV=productionでOKでした。 ためしていませんが以下でも出来るような記事をみつけました。 MySQLにログイン CREATE DATABASE panda production これを実行することでもDBが作成可能。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問