MySQL 压力性能测试(Mysqlslap)工具
本文章介绍一个mysql官方提供的Mysqlslap工具对mysql性能进行测试,有需要的朋友可以参考本文章来测试你的mysql性能与负载哦。
Mysqlslap是从5.1.4版开始的一个MySQL官方提供的压力测试工具。通过模拟多个并发客户端访问MySQL来执行压力测试,同时详细的提供了“高负荷攻击MySQL”的数据性能报告。并且能很好的对比多个存储引擎在相同环境下的并发压力性能差别。
它的使用语法如下:
shell>/usr/local//bin/mysqlslap [options]
常用参数【options】详细介绍:
--concurrency代表并发数量,多个可以用逗号隔开。例如:--concurrency=50,200,500
--engines代表要测试的引擎,可以有多个,用分隔符隔开。例如:--engines=myisam,innodb,memory
--iterations代表要在不同并发环境下,各自运行测试多少次。
--auto-generate-sql 代表用mysqlslap工具自己生成的SQL脚本来测试并发压力。
--auto-generate-sql-add-auto-increment 代表对生成的表自动添加auto_increment列,从5.1.18版本开始,
--auto-generate-sql-load-type 代表要测试的环境是读操作还是写操作还是两者混合的(read,write,update,mixed)
--number-of-queries 代表总共要运行多少条查询。
--debug-info 代表要额外输出CPU以及内存的相关信息。
--number-int-cols 代表示例表中的INTEGER类型的属性有几个。
--number-char-cols代表示例表中的vachar类型的属性有几个。
--create-schema 代表自定义的测试库名称。
--query 代表自定义的测试SQL脚本。
说明:
测试的过程需要生成测试表,插入测试数据,这个mysqlslap可以自动生成,默认生成一个mysqlslap的schema,如果已经存在则先删除。可以用-only-print来打印实际的测试过程,整个测试完成后不会在中留下痕迹。
实验步骤:
练习一:
单线程测试。测试做了什么。
>./bin/mysqlslap -a -uroot -p111111
多线程测试。使用--concurrency来模拟并发连接。
> ./bin/mysqlslap -a -c 100 -uroot -p111111
迭代测试。用于需要多次执行测试得到平均值。
> ./bin/mysqlslap -a -i 10 -uroot -p111111
练习二:
> ./bin/mysqlslap -auto-generate-sql-add-autoincrement -a -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-sql-load-type=read -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-secondary-indexes=3 -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-sql-write-number=1000 -uroot -p111111
> ./bin/mysqlslap --create-schema world -q " count(*) from City" -uroot -p111111
> ./bin/mysqlslap -a -e innodb -uroot -p111111
> ./bin/mysqlslap -a --number-of-queries=10 -uroot -p111111
练习三:
执行一次测试,分别50和100个并发,执行1000次总查询:
> ./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --debug-info -uroot -p111111
50和100个并发分别得到一次测试结果(Benchmark),并发数越多,执行完所有查询的时间越长。为了准确起见,可以多迭代测试几次:
> ./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --debug-info -uroot -p111111
测试同时不同的存储引擎的性能进行对比:
>./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb --debug-info -uroot -p111111

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





You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

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

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.
