Last-modified: 2011-12-26 (月) 01:24:44
MySQL/性能監視を行いたい

概要

性能監視を実現するためにmytopをインストールします。


今回は、MySQLが動いているサーバーとは異なるマシンにインストールします。
同一マシン上の場合でも、とくに変更なく動くと思います。
その場合は@localhostのみ作成したほうがよいかもしれません。

方法

  1. mytopをインストールします。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    apt-get mytop
  2. MySQLにログインし、mytop用MySQLユーザーを作成します。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
    
    -
    |
    !
     
    -
    !
     
    
    -- SELECT権限のみで全DB,全テーブルにアクセス可能で、接続先はLANというユーザーを作成します
    -- 同じユーザーでlocalhost版も作成します
    GRANT SELECT ON *.* TO <ユーザー名>@<ホスト名>;
     
    -- 例.
    GRANT SELECT ON *.* TO mytop@'192.168.50.%';
    GRANT SELECT ON *.* TO mytop@localhost;
  3. パスワードを設定します。
    Everything is expanded.Everything is shortened.
      1
      2
    
    -
    !
    
    -- 2つともパスワードを設定します
    SET PASSWORD FOR <ユーザー名>@<ホスト名>=PASSWORD('<パスワード>');
  4. 権限を再読み込みします。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    FLUSH PRIVILEGES;
  5. MySQLからログアウトし、「~.mytop」(デフォルト設定)を作成します。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
    
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
     
     
     
     
     
    
    # ユーザー名
    user=mytop
    # パスワード
    pass=<パスワード>
    # ホスト名
    host=192.168.50.100
    # データーベース名
    db=mysql
    # 更新間隔(秒)
    delay=5
    # ポート
    port=3306
    socket=
    batchmode=0
    header=1
    color=1
    idle=1
  6. 「~.mytop」のアクセス権を変更します。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    chmod 600 ~/.mytop
  7. 実行します。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
    
    -
    !
     
    -
    !
    
    # デフォルト設定で実行
    mytop
     
    # デフォルト値以外で起動したい場合は、引数で渡します
    mytop -u <ユーザー名> -p <パスワード> -h <ホスト名> -d <データーベース名>

検証時の環境