7
4

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 1 year has passed since last update.

[Laravel]Laravel9.24で追加された dbコマンドを試してみる

Posted at

Laravel9.24のアップデートでdbコマンドが拡張され、データベース情報やテーブル情報が見れるようになったので試してみました。

db:show

データベース情報やテーブル一覧を確認できます。

# php artisan db:show
  MySQL 8 .........................................................  
  Database ................................................ laravel  
  Host ......................................................... db  
  Port ....................................................... 3306  
  Username .................................................. phper  
  URL .............................................................  
  Open Connections .............................................. 1  
  Tables ........................................................ 8  
  Total Size ............................................... 0.66Mb  

  Table ................................................. Size (Mb)  
  telescope_entries_tags ..................................... 0.05  
  telescope_entries .......................................... 0.50  
  failed_jobs ................................................ 0.02  
  telescope_monitoring ....................................... 0.02  
  migrations ................................................. 0.02  
  personal_access_tokens ..................................... 0.02  
  users ...................................................... 0.03  
  password_resets ............................................ 0.02 

db:table

テーブル情報を確認できます。
テーブル選択はCLI上からもできますし、コマンドの引数にテーブル名を指定すればそのテーブルが表示されます。

# php artisan db:table

  Which table would you like to inspect?
  telescope_entries_tags ................................................. 0  
  telescope_entries ...................................................... 1  
  failed_jobs ............................................................ 2  
  telescope_monitoring ................................................... 3  
  migrations ............................................................. 4  
  personal_access_tokens ................................................. 5  
  users .................................................................. 6  
  password_resets ........................................................ 7  
> 6


  users ....................................................................  
  Columns ................................................................ 6  
  Size .............................................................. 0.03Mb  

  Column .............................................................. Type  
  id autoincrement, bigint, unsigned ................................ bigint  
  email string ...................................................... string  
  sei string ........................................................ string  
  mei string ........................................................ string  
  created_at datetime, nullable ................................... datetime  
  updated_at datetime, nullable ................................... datetime  

  Index ....................................................................  
  PRIMARY id ............................................... unique, primary  
  users_email_unique email .......................................... unique  

db:monitor

データベースの状態やコネクション数の確認ができます。

# php artisan db:monitor

  Database name ................................................ Connections  
  mysql ............................................................. [1] OK  

まとめ

基本はクライアントツールで確認すると思いますが、パッと情報を知りたい場合や、環境構築したてでアクセス情報やテーブル情報を一気に確認したい時などは便利そうなので覚えておいて損はないかなと思います。

7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?