$ sysbench /usr/share/sysbench/oltp_read_only.lua help
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
oltp_read_only.lua options: --auto_inc[=on|off] Use AUTO_INCREMENT column as Primary Key (for MySQL), or its alternatives in other DBMS. When disabled, use client-generated IDs [on] --create_secondary[=on|off] Create a secondary index in addition to the PRIMARY KEY [on] --delete_inserts=N Number of DELETE/INSERT combinations per transaction [1] --distinct_ranges=N Number of SELECT DISTINCT queries per transaction [1] --index_updates=N Number of UPDATE index queris per transaction [1] ....
functioncmd_prepare() -- initialize the sysbench mysql driver local drv = sysbench.sql.driver() -- represents the connection to MySQL local con = drv:connect()
local query_str = [[ CREATE TABLE `type_test_tb` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `str` varchar(64) NOT NULL DEFAULT '', `num` int(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=innodb DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC]]
print("Creating table type_test_tb: \n") print(query_str) -- Execute the SQL statement to create the test table con:query(query_str);
query_str = "INSERT INTO type_test_tb (str, num) VALUES"
-- Initialize the batch write channel con:bulk_insert_init(query_str) for i = 1, 10do query_str = string.format("('%s', %d)", tostring(sysbench.rand.pareto(1, 10)), sysbench.rand.pareto(1, 10))
-- Write data to the test table one by one con:bulk_insert_next(query_str) end
-- Disable the batch write channel con:bulk_insert_done() end
functioncmd_cleanup() local drv = sysbench.sql.driver() local con = drv:connect()
con:query("DROP TABLE IF EXISTS type_test_tb") print("Drop table type_test_tb success") end
sysbench.cmdline.options = { storage_engine = { "Storage engine, if MySQL is used", "innodb" }, table_size = { "Number of rows per table", 100000 }, column = { "Column of table by query", "num" }, }
functionthread_init() drv = sysbench.sql.driver() con = drv:connect()
local query_str = string.format("select * from type_test_tb " .. " where %s = ?", sysbench.opt.column) stmt = con:prepare(query_str) localtype = sysbench.opt.column == 'num'and sysbench.sql.type.INT or sysbench.sql.type.VARCHAR
params = {stmt:bind_create(type, 64)} stmt:bind_param(unpack(params)) end
functionthread_done() stmt:close() con:disconnect() end
functionevent() local num = sysbench.rand.pareto(1, sysbench.opt.table_size) num = sysbench.opt.column == 'num'and num ortostring(num); params[1]:set(num)