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;