0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

マイグレーション実行時にmysqlでユーザーを作成していなかった為エラー

Last updated at Posted at 2020-06-02

###マイグレーション実行時エラー

laravel7で新しくプロジェクトを作成したので
とりあえずマイグレーションの実行ししてみたら

エラー発生

  SQLSTATE[HY000] [1045] Access denied for user 'user_name'@'172.20.0.4' (using password: YES) (SQL: select * from information_schema.tables where table_schema =table_name and table_name = migrations and table_type = 'BASE TABLE')

##原因
ただ単に.envに設定したユーザーとパスワードを登録していなかっただけ

##解決方法
mysqlでユーザーを作成をする

create user 'user_name' identified by 'pass';

権限の確認
新規作成したユーザには
何も権限がないことを意味するUSAGEが付いている

mysql> show grants for user_name@'%';
+---------------------------------------+
| Grants for phper@%                    |
+---------------------------------------+
| GRANT USAGE ON *.* TO `user_name`@`%` |
+---------------------------------------+
1 row in set (0.00 sec)

全てのDBが対象となるグローバル権限【CREATE権限】の付与

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'user_name'@'%' WITH GRANT OPTION;

実行後もう一度マイグレーションを実行したら成功

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?