・ Develop applications using Rails -Implementing automatic deployment with Capistrano ・ We are building a server on AWS EC2 -Using MySQL with RDS
In the development environment, I always recreated the database with rails db: migrate: reset, but I implemented it from the question of how to do it in the production environment.
First, use the terminal to go to the hierarchy of your application folder on EC2. Since it is implemented in Capistrano, basically work in the current directory so as not to make mistakes.
[[email protected] App name]cd current
RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rails db:drop
The database has now been cleared.
This time, I will talk on the assumption that MySQL is installed in RDS. First of all, the terminal will continue to connect to mysql with the same directory.
mysql -u (master username) -p -h (endpoint)
"-U" is the user name, "-p" is the password input, and "-h" is the option to indicate the connection destination information.
Check the "Endpoint" in the RDS menu and enter it.
For "Password", enter the password set in "Master password information".
mysql -u root -p -h rds-mysql-server.xxx.ap-northeast-1.rds.amazonaws.com
When you type this command, you will be prompted to enter the password, so when you enter it, the connection to mysql is completed successfully.
Recreate the database with the same name as the deleted application name.
mysql>create database application name;
Run migrate again in the production environment.
bundle exec rails db:migrate RAILS_ENV=production
This completes the database reset. After that, hit the capistrano command in the production environment to finish
bundle exec cap production deploy
Thank you for reading