Optimization of high MySQL Load

Source: Internet
Author: User

The company's website has just completed the revision, optimized the database structure, and used the memcache distributed cache to add MySQL. In the first few days, the database service has not been down for a few days. however, the machine is frequently down over the past few days. this is a big problem that needs to be solved.

The database server hardware is configured with 4 dual-core CPUs and 8 GB memory.

Check the server load (top Command). I think MySQL often has 90% CPUs. I knew earlier that some fields in the data table are not indexed, and the cause of MySQLL load is mainly caused by index problems and some abnormal SQL statements.

How do I know what indexes and SQL problems are caused by MySQL? Tips for Teaching

Edit MySQL configuration file my. cnf with the following lines:
Log_slow_queries =/usr/local/mysql/data/log_slow_queries.log // directory for saving slow statement logs
Long_query_time = 10 // records the SQL query statements that exceed 10 s
Log-queries-not-using-indexes = 1 // records SQL statements that do not use indexes

In this way, slow statements are recorded in the log file.
Tail-f/usr/local/mysql/data/log_slow_queries.log to view logs.
Four Parameters
Query_time: 0 Lock_time: 0 Rows_sent: 1 Rows_examined: 54
The query time lock time indicates the number of rows scanned in the query result.
Mainly look at the statements that scan a large number of rows, and then add the corresponding index to the database.
Optimize abnormal SQL statements
After MySQL load is reduced to more than 20. Okay. It should not be down.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.