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.