• MySQL知识库 :: performance
  • Why is MySQL is using 100% of CPU resources?

  • Discussion

    This could be because of a CPU intensive query or it could be a background thread operation if you are using InnoDB. To determine if it's a problem with a query that is currently running, enter the following SQL statement:

    SHOW FULL PROCESSLIST;
    
    +-------+------+-----------+------+---------+------+-------+-----------------------+
    | Id    | User | Host      | db   | Command | Time | State | Info                  |
    +-------+------+-----------+------+---------+------+-------+-----------------------+
    | 98922 | root | localhost | NULL | Query   | 0    | NULL  | SHOW FULL PROCESSLIST |
    +-------+------+-----------+------+---------+------+-------+-----------------------+
    

    This results shown here are from an unused server. On an active server you would see several rows of results. The bit of information to focus on is the values in the Time field. Look for processes that have been running for a long period of time. Make note of them and determine from where they're originating (e.g., an API script) to see if you can fix the problem at the source. If necessary, use the KILL statement to terminate any processes that won't quit on their own.

    Another source of information for drains on the CPU from MySQL is the slow query log. A link to another MySQL Knowledge Base article on enabling slow query logs and other logs is located in the right.