pt-kill 是一个优秀的kill MySQL连接的一个工具,是percona toolkit的一部分,在因为空闲连接较多导致超过最大连接数、某个有问题的sql导致mysql负载很高时,都需要将一些连接kill掉,这个工具主要就是这个用途。
1. 按user kill
/usr/bin/pt-kill --busy-time 15 --match-user="dbUSER1 | dbUSER2,..." --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
注:测试通过按用户来杀线程,注意--match-user多个用户之间用 | 分隔。
2. 按query来源 host kill
/usr/bin/pt-kill --busy-time 15 --match-host="192.168.10.10 | 192.168.10.11" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
--ignore-host / --match-host
注:测试通过按来源host来杀线程,注意--match-host多个host之间用 | 分隔。
3. 按command kill
/usr/bin/pt-kill --busy-time 15 --match-command="query | Execute" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
/usr/bin/pt-kill --busy-time 15 --ignore-command="sleep | binlogdump" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
注:测试通过按command来杀掉线程,注意command的内容一定要严格匹配大小写,否则会杀不掉。 注意--match-command多个command之间用 | 分隔,否则会失效。
(command有:Query、Sleep、Binlog Dump、Connect、Delayed insert、Execute、Fetch、Init DB、Kill、Prepare、Processlist、Quit、Reset stmt、Table Dump)
4. 按state kill
/usr/bin/pt-kill --busy-time 15 --match-state="Locked | Sending data" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
注:测试通过按state 来杀掉线程,注意state 的内容一定要严格匹配大小写,否则会杀不掉。注意--match-state多个state之间用 | 分隔,否则会失效。
(state类型有:Locked、login、copy to tmp table、Copying to tmp table、Copying to tmp table on disk、Creating tmp table、executing、Reading from net、Sending data、Sorting for order、Sorting result、Table lock、Updating)
5. 按info关键字 kill
/usr/bin/pt-kill --busy-time 15 --match-info="SELECT | DELETE" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
注:测试通过按info来杀掉线程,注意info的内容一定要严格匹配大小写,否则会杀不掉。注意--match-info多个info之间用 | 分隔,否则会失效。
--ignore-info / --match-info
(info可以使用select、update、insert、delete来进行匹配,并可使用"|"进行多项匹配,如"select|SELECT|delete|DELETE|update|UPDATE"
6. 按访问的dbname kill
/usr/bin/pt-kill --busy-time 15 --match-db="db1 | db2" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
--ignore-db / --match-db
注:测试通过按db来杀掉线程,注意db的内容一定要严格匹配大小写,否则会杀不掉。注意--match-db多个db之间用 | 分隔,否则会失效。
另: Action:
--kill 杀掉连接并且退出
--kill-query 只杀掉连接执行的语句,但是线程不会被终止
以上就是pt-kill 常用杀进程参数介绍_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools
