用percona-toolkit为MySQL收集系统和性能信息的教程_MySQL
系统类工具
1. pt-diskstats
功能介绍:
是一个对GUN/LINUX的交互式监控工具
用法介绍:
pt-diskstats [OPTION...] [FILES]
为GUN/LINUX打印磁盘io统计信息,和iostat有点像,但是这个工具是交互式并且比iostat更详细。可以分析从远程机器收集的数据。
使用示例:
范例1:查看本机所有的磁盘的状态情况:
pt-diskstats
范例2:只查看本机sda2磁盘的状态情况
pt-diskstats --devices-regex sda2
2. pt-fifo-split
功能介绍:
模拟切割文件并通过管道传递给先入先出队列而不用真正的切割文件
用法介绍:
pt-fifo-split [options] [FILE ...]
pt-fifo-split读取大文件中的数据并打印到fifo文件,每次达到指定行数就往fifo文件中打印一个EOF字符,读取完成以后,关闭掉fifo文件并移走,然后重建fifo文件,打印更多的行。这样可以保证你每次读取的时候都能读取到制定的行数直到读取完成。注意此工具只能工作在类unix操作系统。这个程序对大文件的数据导入数据库非常有用,具体的可以查看http://www.mysqlperformanceblog.com/2008/07/03/how-to-load-large-files-safely-into-innodb-with-load-data-infile/。
使用示例:
范例1:一个每次读取一百万行记录的范例:
pt-fifo-split --lines 1000000 hugefile.txt while [ -e /tmp/pt-fifo-split ]; do cat /tmp/pt-fifo-split; done
范例2:一个每次读取一百万行,指定fifo文件为/tmp/my-fifo,并使用load data命令导入到mysql中:
pt-fifo-split infile.txt --fifo /tmp/my-fifo --lines 1000000 while [ -e /tmp/my-fifo ]; do mysql -e "set foreign_key_checks=0; set sql_log_bin=0; set unique_checks=0; load data local infile '/tmp/my-fifo' into table load_test fields terminated by '\t' lines terminated by '\n' (col1, col2);" sleep 1; done
3. pt-summary
功能介绍:
友好地收集和显示系统信息概况,此工具并不是一个调优或者诊断工具,这个工具会产生一个很容易进行比较和发送邮件的报告。
用法介绍:
pt-summary
原理:此工具会运行和多命令去收集系统状态和配置信息,先保存到临时目录的文件中去,然后运行一些unix命令对这些结果做格式化,最好是用root用户或者有权限的用户运行此命令。
使用示例:
范例1:查看本地系统信息概况
pt-summary
4. pt-stalk
功能介绍:
出现问题的时候收集mysql的用于诊断的数据
用法介绍:
pt-stalk [OPTIONS] [-- MYSQL OPTIONS]
pt-stalk等待触发条件触发,然后收集数据帮助错误诊断,它被设计成使用root权限运行的守护进程,因此你可以诊断那些你不能直接观察的间歇性问题。默认的诊断触发条件为SHOW GLOBAL STATUS。也可以指定processlist为诊断触发条件 ,使用--function参数指定。
使用示例:
范例1:指定诊断触发条件为status,同时运行语句超过20的时候触发,收集的数据存放在/tmp/test目录下:
pt-stalk --function status --variable Threads_running --threshold 20 --dest /tmp/test -- -uroot -pzhang@123 -h192.168.3.135
范例2:指定诊断触发条件为processlist,超过20个状态为statistics触发,收集的数据存放在/tmp/test目录下:
pt-stalk --function processlist --variable State --match statistics --threshold 20 --dest /tmp/test -- -uroot -pzhang@123 -h192.168.3.135
贴一下达到触发条件以后收集的信息:
2012_06_04_17_31_49-df 2012_06_04_17_31_49-disk-space 2012_06_04_17_31_49-diskstats 2012_06_04_17_31_49-hostname 2012_06_04_17_31_49-innodbstatus1 2012_06_04_17_31_49-innodbstatus2 2012_06_04_17_31_49-interrupts 2012_06_04_17_31_49-log_error 2012_06_04_17_31_49-lsof 2012_06_04_17_31_49-meminfo 2012_06_04_17_31_49-mutex-status1 2012_06_04_17_31_49-mysqladmin 2012_06_04_17_31_49-netstat 2012_06_04_17_31_49-netstat_s 2012_06_04_17_31_49-opentables1 2012_06_04_17_31_49-opentables2 2012_06_04_17_31_49-output 2012_06_04_17_31_49-pmap 2012_06_04_17_31_49-processlist 2012_06_04_17_31_49-procstat 2012_06_04_17_31_49-procvmstat 2012_06_04_17_31_49-ps 2012_06_04_17_31_49-slabinfo 2012_06_04_17_31_49-sysctl 2012_06_04_17_31_49-top 2012_06_04_17_31_49-trigger 2012_06_04_17_31_49-variables 2012_06_04_17_31_49-vmstat 2012_06_04_17_31_49-vmstat-overall
性能类工具
1. pt-index-usage
功能介绍:
从log文件中读取插叙语句,并用explain分析他们是如何利用索引。完成分析之后会生成一份关于索引没有被查询使用过的报告。
用法介绍:
pt-index-usage [OPTION...] [FILE...]
可以直接从慢查询中获取sql,FILE文件中的sql格式必须和慢查询中个是一致,如果不是一直需要用pt-query-digest转换一下。也可以不生成报告直接保存到数据库中,具体的见后面的示例
使用示例:
从满查询中的sql查看索引使用情况范例:
pt-index-usage /data/dbdata/localhost-slow.log --host=localhost --user=root --password=zhang@123
将分析结果保存到数据库范例:
pt-index-usage /data/dbdata/localhost-slow.log --host=localhost --user=root --password=zhang@123 --no-report --create-save-results-database
使用--create-save-results-database会自动生成数据库和表来保存结果。
2. pt-pmp
功能介绍:
为查询程序执行聚合的GDB堆栈跟踪,先进性堆栈跟踪,然后将跟踪信息汇总。
用法介绍:
pt-pmp [OPTIONS] [FILES]
使用示例:
pt-pmp -p 21933 pt-pmp -b /usr/local/mysql/bin/mysqld_safe
3. pt-visual-explain
功能介绍:
格式化explain出来的执行计划按照tree方式输出,方便阅读。
用法介绍:
pt-visual-explain [OPTION...] [FILE...]
option请参阅官方网站,这里不一一例举!
使用示例:
查看包含explain结果的aaa文件的范例:
pt-visual-explain aaa
查看包含查询语句的aaa文件的范例:
pt-visual-explain --connect aaa --user=root --password=zhang@123
通过管道直接查看explain输出结果的范例:
mysql -uroot -pzhang@123 -e "explain select email from test.collect_data where id=101992419" |pt-visual-explain

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
