Here is basic mysqlslap Tutorial to perform MySQL stress test. MySQL comes with mysqlslap, a benchmarking tool which can help you to test database servers. For MySQL optimization test, we usually use Major Hayden’s MySQL Tuner Script. This mysqlslap tutorial is for the beginners. One should read in the way we normally handle MySQL database from command line.
mysqlslap Tutorial : First Things First
Unlike Major Hayden’s script, this benchmarking tool should be used on a test server with the same specifications of the original database server in question and copy of the database. You should not perform the test on Cloud database as a service. We recommend using a 1 GB PVHVM instance at minimum to test if you are testing on Rackspace. This tool mysqlslap, emulate a large number of connections hitting the application server at the same time. Testing parameters are configurable, so we can fine-tune the original database server or decide whether there is need of scaling.
You can create an Image of the working production server and simply spin a server on Rackspace. In that case, you need not to import anything. It is the exact replica copy.
The user is newer, but understand the basics from the linked previously published article. We are using an Ubuntu instance. Follow the official guide to install only MySQL :
mysqlslap Tutorial : First Steps After Building The Server and Importing the Database
So, you have imported the database. Optionally, you can create an user with all privileges from MySQL interactive mode :
create user systemtest identified by 'password';
# change password
grant all on *.* to systemtest;
The syntax to test a database goes like this :
mysqlslap --user=USERNAME --PASSWORD --host=localhost/IP ADDRESS --auto-generate-sql --verbose
# change USERNAME, PASSWORD and localhost/IP ADDRESS to right one
The above tests against a single client and output will go like this :
Average number of seconds to run all queries: 0.001 seconds
Minimum number of seconds to run all queries: 0.001 seconds
Maximum number of seconds to run all queries: 0.001 seconds
Number of clients running queries: 1
Average number of queries per client: 0
We can add variables as flag with the above command like :
# 40 concurrent users
# 20 times queries are executed
# number of var char
# number of columns
# full command
mysqlslap --user=USERNAME --PASSWORD --host=localhost --concurrency=40 --iterations=20 --auto-generate-sql --verbose
We can go a bit advanced with SELECT variable to be more specific :
mysqlslap --user=root --password --host=localhost --concurrency=40 --iterations=10 --create-schema=wordpress --query="SELECT * FROM wp_commentmeta;" --verbose
# change the variable
This is a very basic and safe guide to test your MySQL database, there are official guide and books to use the tool more efficiently. Get used with this basic, then you actually can perform on a production server with the log on. Without a bit practice, it is risky to use mysqlslap on production server.
Additionally we can measure the parameters like load average, CPU and memory consumption on Rackspace Cloud Monitoring tool. Application servers, specially for WordPress sucks the memory.
Follow the Author of this article :