0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

docker + Laravel + MySQL環境下のDB名称変更

Last updated at Posted at 2025-03-29

はじめに

個人開発中のアプリでDBの名前を変える必要があったので、備忘録的にやり方を残しておきます。
DB内のデータは引き継がないで削除します。

作業手順

旧DBの削除

docker compose exec [コンテナ名] bash
mysql -u root
mysql> drop database 削除したいデータベース名;

.envの変更

.envのDB名定義部分を書き換え

DB_DATABASE=new_database_name

変更後アプリケーションコンテナに入り、Laravelの設定キャッシュをクリア

docker compose exec [コンテナ名] bash
php artisan config:clear

権限の再設定

DBコンテナに入り、MySQLの GRANT 設定を修正

docker compose exec [コンテナ名] bash
mysql -u root
~ここから権限設定~
mysql> GRANT ALL PRIVILEGES ON new_database_name.* TO '[MySQLのユーザー名]'@'%';
mysql> FLUSH PRIVILEGES;

マイグレーション実行

php artisan migrate:fresh --seed

以上で完了です。
DBの名前を変えたいことはそうそう無いかもしれませんが、、、

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?