在mysql5.1以后的版本:
http://mysql.isu.edu.tw/Downloads/MySQL-5.1/MySQL-client-community-5.1.29-0.rhel5.i386.rpm
客戶端帶了個工具mysqlslap可以對mysql進行壓力測試:
可以使用mysqlslap --help來顯示使用方法:
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
--concurrency代表并發數量,多個可以用逗號隔開,當然你也可以用自己的分隔符隔開,這個時候要用到--delimiter開關。
--engines代表要測試的引擎,可以有多個,用分隔符隔開。
--iterations代表要運行這些測試多少次。
--auto-generate-sql 代表用系統自己生成的SQL腳本來測試。
--auto-generate-sql-load-type 代表要測試的是讀還是寫還是兩者混合的(read,write,update,mixed)
--number-of-queries 代表總共要運行多少次查詢。每個客戶運行的查詢數量可以用查詢總數/并發數來計算。比如倒數第二個結果2=200/100。
--debug-info 代表要額外輸出CPU以及內存的相關信息。
--number-int-cols : Number of INT columns to create in table if specifying
--auto-generate-sql.
--number-char-cols 意思同上。
--create-schema 代表自己定義的模式(在MySQL中也就是庫)。
--query The file or string containing the SELECT statement to use for retrieving data.
--only-print 如果只想打印看看SQL語句是什么,可以用這個選項。
mysqlslap -h192.168.3.18 -P3306 --concurrency=100 --iterations=1 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=myisam --number-of-queries=10 --debug-info -umysql -p123
或:
mysqlslap -h192.168.3.18 -P4040 --concurrency=100 --iterations=1 --create-schema='test' --query='select * from test;' --number-of-queries=10 --debug-info -umysql -p123
要是看到底做了什么可以加上:--only-print
Benchmark
Average number of seconds to run all queries: 25.225 seconds
Minimum number of seconds to run all queries: 25.225 seconds
Maximum number of seconds to run all queries: 25.225 seconds
Number of clients running queries: 100
Average number of queries per client: 0
以上表明100個客戶端同時運行要25秒
文章來源于領測軟件測試網 http://www.kjueaiud.com/