LoginSignup
54
60

More than 5 years have passed since last update.

運用MySQL ~その1~ DB状態確認

Posted at

MySQLの状態を確認する

mysqlコマンドラインツールでSQLを発行し、MySQLの状態を確認する。
状態確認に最低限必要と思われるコマンドのみ記載しています。

mysqlコマンドで接続

localhostのMySQLにログイン

mysql -u[user] -p (--socket=[socketfile])

リモートホストのMySQLにログイン

mysql -u[user] -p[passwd] -h[hostname]

MySQL コマンドラインツール

DBの状態、構成を確認する

実行中クエリを確認する

  • show 構文で確認
    mysql:query
    show [full] processlist;

    SHOW PROCESSLIST 構文

  • information_schemaから確認
    where句で絞るなど、showコマンドより柔軟に接続情報を取得できる。

    • processlistを取得
    query
    select * from information_schema.processlist;
    
    • where句で絞る
    query
    select * from information_schema.processlist where HOST = '[remote_host]';
    

    MySQL5.6 PROCESSLISTテーブル
    MySQL5.6 information_schema

DB構成を確認

  • DB一覧を取得

    query
    show databases;
    
  • クエリを実行するDBを指定

    query
    use [db_name];
    
  • テーブル一覧を表示

    query
    show tables;
    
  • テーブル詳細を表示

    query
    show table status;
    
  • テーブル構成(CREATE TABLE文)を表示

    query
    show create table [table_name];
    

SHOW 構文

権限を確認

  • 権限一覧を取得 (user,hostでソートしておくと見やすい)

    query
    select user,host from mysql.user order by user,host;
    
  • 権限の詳細を取得

    query
    show grants for `[user]`@`[host]`;
    

    SHOW GRANTS 構文

MySQLの設定を確認

query
show global variables;

SHOW VARIABLES 構文

MySQLの状態を確認

query
show global status;

SHOW STATUS 構文

レプリケーション設定、状態を確認

query
show slave status\G

SHOW SLAVE STATUS 構文

innodbの詳細確認

query
show engine innodb status\G

InnoDB 標準モニターおよびロックモニターの出力

54
60
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
54
60