By javadroid
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!
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.
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:
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.
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.
mysql -u root -p
Replace `root` with your MySQL username if different.
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.
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.
Examine Query Execution: For each suspicious query, consider:
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 ...;
MySQL Tuner: Consider using tools like MySQLTuner or Percona Toolkit to analyze your MySQL server performance and get recommendations for tuning.
Server Monitoring Tools: Use server monitoring tools to keep an eye on overall system health and resource usage.
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.