Report this

What is the reason for this report?

how to find each process details of MySQL?

Posted on May 28, 2017

Hi ,

I have a problem with my MySQL. I’ve about 10 MySQL processes which totally consumed 360% of my CPU usage. WOW!! so it causes overloading in my OS. I want to find the detail information of each MySQL process so that I could find which process consumed my system.

how can I do that?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@javadroid

You can use this command top -p <pid> to get details about a single process.

Use pgrep mysqld to find the process IDs of your mysql server then use the first command to find details about each process.

Hope this helps.

@javadroid

There’s a few tools you can use to gauge performance, or check resource usage. If you’re using the defaults for MySQL though, chances are, that’s one issue that’s leading to the spikes. The defaults for MySQL aren’t meant for production use and aren’t really optimized for more than light traffic.

htop

apt-get -y install htop

htop will provide a more detailed look with better sorting than standard top. You can hit F6 to sort by CPU, MEM, etc. You can also use F6 to expand the process tree and view child processes.

mytop

apt-get -y install mytop

mytop will give you information about threads, queries, key performance, etc in real time.

mysqltuner

https://github.com/major/MySQLTuner-perl

MySQL Tuner isn’t a monitoring agent, so to speak, as much as it is a tool to gauge performance and help optimize your configuration. It’ll make suggestions on how you can improve performance, as well as detail how your current configuration is working for you. Its very detailed.

The one thing to note about MySQL Tuner is that MySQL needs to be running for at least 24 hours before each run so that it can gather proper stats. So if you run MySQL Tuner, and then make a few changes, unless those changes cause larger issues than you’re already having, you need to give it a bit of time before running it again.

MySQL CLI

mysql -u root -e 'show processlist'

You can also just run this command from the CLI, though mytop would be a better option since it’s continuous and live, whereas this is a one-off command.

Heya,

To diagnose high CPU usage caused by MySQL processes, you can use a combination of system and MySQL-specific commands. Here’s a step-by-step approach to identify and analyze the MySQL processes consuming high CPU resources:

Step 1: Identify MySQL Processes using System Commands

  1. Top Command: Use the top command to view the processes consuming the most CPU. You can identify MySQL processes by their command name, usually mysqld.
top
In the `top` interface, press `Shift+P` to sort by CPU usage.
  1. PS Command: Alternatively, use the ps command to get more detailed information about MySQL processes:
ps -aux | grep 'mysqld'
This command filters out MySQL processes and shows their CPU usage, memory usage, process ID (PID), and other details.

Step 2: Investigate MySQL Processes

  1. Log in to MySQL: Log in to your MySQL server:
mysql -u root -p
Replace `root` with your MySQL username if different.
  1. Show Processlist: In the MySQL prompt, use the SHOW PROCESSLIST command to view the current MySQL threads:
SHOW FULL PROCESSLIST;
This will show you queries that are currently running or in the queue to be executed.

Step 3: Analyze Specific Queries

  1. Identify Long-Running Queries: Look for queries with a long Time value in the SHOW PROCESSLIST output. These are often the culprits for high CPU usage.

  2. Examine Query Execution: For each suspicious query, consider:

    • What the query does.
    • How it interacts with your database schema.
    • Whether it involves large tables or complex joins.
  3. Use EXPLAIN: Use the EXPLAIN command before a SQL query to get information about how MySQL executes it. This can provide insights into inefficiencies in the query or the need for indexes:

EXPLAIN SELECT * FROM your_table WHERE ...;

Step 4: Monitor Server Performance

  1. MySQL Tuner: Consider using tools like MySQLTuner or Percona Toolkit to analyze your MySQL server performance and get recommendations for tuning.

  2. Server Monitoring Tools: Use server monitoring tools to keep an eye on overall system health and resource usage.

Additional Tips

  • Optimize Queries: Optimize slow queries by rewriting them or adding indexes where necessary.
  • Check Configuration: Review your MySQL server configuration for settings that could be adjusted to better suit your workload, such as buffer sizes and limits.
  • Upgrade Hardware: If your server is consistently under high load, consider upgrading your server hardware or moving to a server with better resources.

By following these steps, you should be able to pinpoint which MySQL processes are consuming high CPU and take steps to mitigate the issue. Remember that database performance tuning can be a complex task and sometimes requires iterative adjustments and monitoring.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.