Closed CarbazochromeT closed 1 year ago
開発環境でrails db:create
やrails db:migrate
などのコマンドは正常に動作していますか?
開発環境でのマイグレーションは行えておりません。 developmentの方のデータベースが消えてしまったみたいです。
$ rails db:create
There is an issue connecting to your database with your username/password, username: root.
Please check your database configuration to ensure the username/password are valid.
Couldn't create 'drug_app5_development' database. Please check your configuration.
rails aborted!
ActiveRecord::DatabaseConnectionError: There is an issue connecting to your database with your username/password, username: root.
Please check your database configuration to ensure the username/password are valid.
Caused by:
Mysql2::Error::ConnectionError: Access denied for user 'root'@'localhost' (using password: YES)
Tasks: TOP => db:create
(See full trace by running task with --trace)
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [12:40:43] C:1
$ rails db:migrate
rails aborted!
ActiveRecord::DatabaseConnectionError: There is an issue connecting to your database with your username/password, username: root.
Please check your database configuration to ensure the username/password are valid.
Caused by:
Mysql2::Error::ConnectionError: Access denied for user 'root'@'localhost' (using password: YES)
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
ホスト名を指定するとMySQLにログインできるようです。
$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [12:45:23] C:1
$ mysql -u root -h 127.0.0.1
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 8.1.0 Homebrew
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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のrootに対してパスワードを設定していますか。設定していたら、その設定とdatabase.yml内のpasswordが一致しているか確認とかしてみてください。
余談ですが、Herokuはmysql以外でもpostgresqlでもデプロイできるので、そちらを検討するのもありかと思います。(インフラ入門のアプリケーションのデプロイ辺りが参考になるかと思います)
すみません、MySQLWorkbenchの方でパスワードを設定し直しましたらrootの方にログインできました。
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 8.1.0 Homebrew
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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> exit
exit
^C
mysql> exit
Bye
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [13:59:33]
$ rails db:migrate
rails aborted!
ActiveRecord::NoDatabaseError: We could not find your database: drug_app5_development. Which can be found in the database configuration file located at config/database.yml.
To resolve this issue:
- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.
To create your database, run:
bin/rails db:create
Caused by:
Mysql2::Error: Unknown database 'drug_app5_development'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [13:59:58] C:127
$ rails db:create
Created database 'drug_app5_development'
There is an issue connecting to your database with your username/password, username: .
Please check your database configuration to ensure the username/password are valid.
Couldn't create 'drug_app5_test' database. Please check your configuration.
rails aborted!
ActiveRecord::DatabaseConnectionError: There is an issue connecting to your database with your username/password, username: .
Please check your database configuration to ensure the username/password are valid.
Caused by:
Mysql2::Error::ConnectionError: Access denied for user 'root'@'localhost' (using password: NO)
Tasks: TOP => db:create
(See full trace by running task with --trace)
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [14:00:07] C:1
$ rails db:create
Database 'drug_app5_development' already exists
There is an issue connecting to your database with your username/password, username: .
Please check your database configuration to ensure the username/password are valid.
Couldn't create 'drug_app5_test' database. Please check your configuration.
rails aborted!
ActiveRecord::DatabaseConnectionError: There is an issue connecting to your database with your username/password, username: .
Please check your database configuration to ensure the username/password are valid.
Caused by:
Mysql2::Error::ConnectionError: Access denied for user 'root'@'localhost' (using password: NO)
Tasks: TOP => db:create
(See full trace by running task with --trace)
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [14:02:01] C:1
$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
Rootでの設定を変えた後、再起動したらサーバーが立ち上がらなくなってしまいました。
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [14:06:57] C:1
$ sudo mysql.server restart
Password:
Shutting down MySQL
... ERROR! The server quit without updating PID file (/opt/homebrew/var/mysql/flarenoMacbook-Air.local.pid).
ERROR! Failed to stop running server, so refusing to try to start.
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [14:07:04] C:1
$ sudo vi /etc/my.cnf
# anago @ flarenoMacbook-Air in ~/workspace/runteq/応用編/drug_app5 on git:deploy x [14:07:40]
$ sudo mysql.server restart
Shutting down MySQL
. SUCCESS!
Starting MySQL
. ERROR! The server quit without updating PID file (/opt/homebrew/var/mysql/flarenoMacbook-Air.local.pid).
データベースに関してはもう少しMySQLでなんとか頑張ってみたいと思います。
現在MySQLのエラーログを確認したらこのような内容になっておりました。
2023-10-13T05:28:19.981653Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2023-10-13T05:28:20.133292Z 0 [Warning] [MY-010097] [Server] Insecure configuration for --secure-fi
le-priv: Current value does not restrict location of generated files. Consider setting it to a vali
d, non-empty path.
2023-10-13T05:28:20.133340Z 0 [System] [MY-010116] [Server] /opt/homebrew/opt/mysql/bin/mysqld (mys
qld 8.1.0) starting as process 97179
2023-10-13T05:28:20.135332Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 becau
se file system for /opt/homebrew/var/mysql/ is case insensitive
2023-10-13T05:28:20.142136Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-10-13T05:28:20.214538Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-10-13T05:28:20.306832Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-10-13T05:28:20.306858Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to suppor
t TLS. Encrypted connections are now supported for this channel.
2023-10-13T05:28:20.308062Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file:
Location '/opt/homebrew/var/mysql' in the path is accessible to all OS users. Consider choosing a
different directory.
2023-10-13T05:28:20.309806Z 0 [ERROR] [MY-000067] [Server] unknown variable 'validate-password=OFF'
.
2023-10-13T05:28:20.309924Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-10-13T05:28:21.391003Z 0 [System] [MY-010910] [Server] /opt/homebrew/opt/mysql/bin/mysqld: Shu
:
下記のエラーメッセージが特に気になっています。
[Server] Insecure configuration for --secure-fi
le-priv: Current value does not restrict location of generated files. Consider setting it to a vali
d, non-empty path.
[Server] Setting lower_case_table_names=2 becau
se file system for /opt/homebrew/var/mysql/ is case insensitive
[Server] Insecure configuration for --pid-file:
Location '/opt/homebrew/var/mysql' in the path is accessible to all OS users. Consider choosing a
different directory.
Herokuからアプリ自体のデプロイは成功したのですが、productionの方のデータベースへのマイグレーションを行うことができず、行き詰まってしまっている状況です。 どなたがご助言をお願いいたします。
試したこと
HerokuからMySQLへ接続ができなかったため一度Homebrew経由でインストールしたMySQLをこれらのコマンドを使用してアンインストール、MySQLをインストールいたしました。
上記のコマンドでMySQLがいないことを確認し、再度インストールを行い、ローカルへ接続いたしました。
https://qiita.com/akiko-pusu/items/aef52b723da2cb5dc596
ローカルからのMySQLへの接続は完了したのですが、heroku経由でマイグレーションを行おうとするとやはり
Mysql2::Error: Table 'qw7n2t3o8f78mknx.your_table_name' doesn't exist
というエラーが発生してしまいます。 どなたかご助言をお願いいたします。heroku configのデータはどなたか閲覧次第消します。
なお、DATABASE URLに関しましてはmysql2を指定しています。 https://qiita.com/shizimi_50/items/3f0ca56649dc8f968267
上記のコマンドを利用しています。