MySQL Primer--the Usage of Mysqladmin--ping,status,processlist,kill,shutdown

来源:互联网 发布:易语言网页数据采集 编辑:程序博客网 时间:2024/06/06 08:27
1.Using mysqladmin
  *Checking  MySQL server status
    command:
       mysqladmin -p ping;
       mysqladmin -p status;

 

  eg1:

     fish@piniheaven:~$sudo mysqladmin -p ping
     [sudo] password for fish:
     Enter password:
     mysqld is alive
   
   eg2:
     fish@piniheaven:~$ sudo mysqladmin -p status
     Enter password:
     Uptime: 3272  Threads: 1  Questions: 111  Slow queries: 0  Opens: 175  Flush tables: 1  Open tables: 42  Queries per second avg: 0.033

 
  *find out what connections are active to the MySQL server
     command:
       mysqladmin -p processlist;

 

  eg3:

     fish@piniheaven:~$ sudo mysqladmin -p processlist
     Enter password:
       +----+------+-----------+------------+---------+------+-------+------------------+
       | Id  | User | Host      | db         | Command | Time | State | Info         |
       +----+------+-----------+------------+---------+------+-------+------------------+
       | 46 | root | localhost | MyDatabase | Sleep   | 100  |       |                  |
       | 50 | root | localhost |            | Query   | 0    |       | show processlist |
      +----+------+-----------+------------+---------+------+-------+------------------+
    explanation:
           From above, we can see a user named root is connected from localhost to the MyDatabase database


   *kill a connection
     command:
        mysqladmin kill <id>

 

 eg4:

     fish@piniheaven:~$sudo mysqladmin -p kill 46
     Enter password:
     fish@piniheaven:~$ sudo mysqladmin -p processlist
     Enter password:
      +----+------+-----------+----+---------+------+-------+------------------+
     | Id | User | Host      | db | Command | Time | State | Info         |
     +----+------+-----------+----+---------+------+-------+------------------+
     | 52 | root | localhost |    | Query   | 0    |       | show processlist |
     +----+------+-----------+----+---------+------+-------+------------------+
    explanation:
       after executing the command,we can see that the connection by id 46  no longer exists:
       At the sametime,when the root user with an id 46 who connected via the MySQL CLI try to do someting,for example:
       SHOW DATABASES;Unfortunately,it didn't work!He would received the following messages:
       ERROR 2006 (HY000): MySQL server has gone awayNo connection. Trying to reconnect...
 
  *shoutdown the server
     command:
       mysqladmin -p shutdown