LoginSignup
3
5

More than 5 years have passed since last update.

MySQLで使いそうな物メモ

Last updated at Posted at 2017-07-13

MySQLを使う事になったので使いそうな物をメモってみた。

テーブル一覧を見たい

全スキーマ

select  table_schema, table_name from information_schema.tables;

今のスキーマのみ

show tables;

index名の一覧を取得する

全スキーマ

select distinct table_schema,table_name,index_name from information_schema.statistics where index_name  <> 'PRIMARY';

対象のテーブルのみ

show index from information_schema.statistics\G

テーブル定義を読む

show create table information_schema.statistics;

ついでにindexも出てくる

カラム名一覧を取得したい

select table_schema, table_name, column_name,data_type from information_schema.columns order by table_schema, table_name, column_name;

@ran さんのコメントより

desc mysql.user;

データ容量を見る


select round(sum(data_length) / 1024 / 1024, 1) as 'data_volume(MB)' from information_schema.tables;

スキーマごとのデータ容量

select table_schema, round(sum(data_length) / 1024 / 1024, 1) as 'data_volume(MB)' from information_schema.tables group by table_schema;

ユーザー名一覧

@tokino さんのコメントより

 select user, host  from mysql.user;
3
5
3

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
3
5