Mysql壓測工具mysqlslap 講解

在mysql5.1之後的版本:客戶端帶了個工具mysqlslap能夠對mysql進行壓力測試html

能夠使用mysqlslap --help來顯示使用方法:mysql

Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnfsql

--concurrency表明併發數量,多個能夠用逗號隔開,concurrency=10,50,100, 併發鏈接線程數分別是十、50、100個併發。數據庫

--engines表明要測試的引擎,能夠有多個,用分隔符隔開。
--iterations表明要運行這些測試多少次。
--auto-generate-sql 表明用系統本身生成的SQL腳原本測試。
--auto-generate-sql-load-type 表明要測試的是讀仍是寫仍是二者混合的(read,write,update,mixed)
--number-of-queries 表明總共要運行多少次查詢。每一個客戶運行的查詢數量能夠用查詢總數/併發數來計算。
--debug-info 表明要額外輸出CPU以及內存的相關信息。
--number-int-cols :建立測試表的 int 型字段數量
--auto-generate-sql-add-autoincrement : 表明對生成的表自動添加auto_increment列,從5.1.18版本開始
--number-char-cols 建立測試表的 char 型字段數量。
--create-schema 測試的schema,MySQL中schema也就是database。
--query  使用自定義腳本執行測試,例如能夠調用自定義的一個存儲過程或者sql語句來執行測試。
--only-print 若是隻想打印看看SQL語句是什麼,能夠用這個選項。併發

mysqlslap -u root -p --concurrency=100 --iterations=1 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=myisam --number-of-queries=10工具

或:測試

指定數據庫和sql語句:線程

mysqlslap -h localhost -P 123456 --concurrency=100 --iterations=1 --create-schema='mysql' --query='select * from user;' --number-of-queries=10 -u root -pdebug

要是看到底作了什麼能夠加上:--only-printhtm

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秒

 

再如:

mysqlslap -uroot -p123456 --concurrency=100 --iterations=1 --engine=myisam --create-schema='haodingdan112' --query='select *  From order_boxing_transit where id = 10' --number-of-queries=1 --debug-info

相關文章
相關標籤/搜索