Mysql problem-solving ideas

Database level

A: check for problems common tools

1: msyqladmin: MySQL client, you can manage the operation

2: mysqlshow: powerful shell commands to view

3: show [SESSION | GLOBAL] variables: view the database parameter information

4: SHOW [SESSION | GLOBAL] STATUS: view status information database

5: information_schema: obtain metadata method

6: SHOW ENGINE INNODB STATUS: All state Innodb engines

7: SHOW PROCESSLIST: View current status of all connected session

8: explain: get the query execution plan

9: show index: see table index information

10: slow-log: Record slow query

11: mysqldumpslow: analysis slowlog file

 

Two: Solutions

General emergency tuning ideas: apply for a sudden business Caton, unable to carry out normal business processing needs to be addressed immediately Scene

1:show processlist;

2:explain  select id ,name from stu where name='clsn'; # ALL  id name age  sex;

select id, name from stu where id = 2-1 functions result set> 30; show index from table;

3: Implementation Plan judgment, indexing issues (there is not, is reasonable) or the statement itself is the problem;

4: show status like '% lock%'; # query lock status

kill SESSION_ID; # kill a problem session.

Conventional tuning ideas: for cyclical business Caton, for example, 10-11 am every business especially slow, but can also be used over a period of time just fine.

1: View slowlog, analysis slowlog, analyze slow query statement;

2: according to certain priorities, one by one investigation all slow statements;

3: Analyze top SQL, perform explain debugging, see the statement execution time;

4: Adjust index or statement itself.

 

 

System level

A: check for problems common tools

Cpu方面:vmstat、sar top、htop、nmon、mpstat;

Memory: free, ps-aux;

IO devices (disk, network): iostat, ss, netstat, iptraf, iftop, lsof;

vmstat command Description:

1) Procs: r shows how many processes are waiting for CPU time. b displayed in the number of non-interrupted sleep process. Waiting for I / O.

2) Memory: swpd display is switched to the disk number data block. Data block, buffering the user data block is not used, the number of data blocks for the operating system.

3) Swap: switching from the second operating system memory and disk memory to the amount of exchanged data block from the disk. s0 and s1 are preferably 0.

4) Io: b1 is read from the second device, the device number of data blocks written to b0. It reflects the disk I / O.

5) System: shows the number of interrupt number (in) per occurrence and context switching (cs) of.

6) Cpu: displaying a running user code, system code, is idle, waiting Cpu time of I / O.

iostat Command Description:

Examples of command: iostat -dk 1 5

       iostat -d -k -x 5 (see capacity utilization (% util) and response time (the await))

1) tps: the number of transfers per second device. "First transmission" means "one I / O request." A plurality of logical requests may be combined into "one I / O request."

The maximum number of IO hardware factory when the factory defined by a second: 2) iops

3) "first transmission" requested size is unknown.

4) kB_read / s: the amount of data read from the second device (drive expressed);

5) KB_wrtn / s: the amount of data to a second device (drive expressed) written;

6) kB_read: The total amount of data read;

7) kB_wrtn: the amount of the total number of data writing; these units are Kilobytes.

 

Two: system-level solutions to problems

Do you think in the end good load high, low or good? In the actual production, generally considered Cpu as long as no more than 90% have no problem.

We do not dismiss these special cases below:

Cpu high load, low load IO

1) Memory is not enough;

2) poor performance disk;

3) SQL problem ---> to the database layer, SQL issue further investigation;

4) IO a problem (critical to the disk, raid poorly designed, raid downgrade, lock, tps too high in unit time);

5) tps too high: a large number of small data IO, a large number of full table scan.

IO high load, low load Cpu

1) a large number of small IO writes:

the autocommit, a large number of small IO; a maximum number of IO value IO / PS, disk, hardware factory when a second defined by the manufacturer.

2) a large number of large IO writes: the problem is relatively large chance of SQL

IO and have a high cpu load

The problem is not hardware or SQL.

 

Published 50 original articles · won praise 2 · Views 2246

Guess you like

Origin blog.csdn.net/eafun_888/article/details/104738612