Benchmarking a MariaDB or MySQL server provides a repeatable way to measure throughput and latency before hardware changes, configuration tuning, or version upgrades land in production.

The sysbench OLTP tests connect using the MySQL protocol, create benchmark tables, and execute transactions with configurable concurrency (threads), duration, and dataset size using scripts commonly installed under /usr/share/sysbench.

Synthetic load is ideal for apples-to-apples comparisons, but results swing with dataset sizing, caching, and connection path, so keep test parameters stable, avoid mixing production traffic into the run, and remove benchmark artifacts after measurement.

Steps to benchmark MariaDB and MySQL performance:

  1. Run the benchmark on a staging clone or a dedicated test instance.

    An OLTP workload can saturate CPU, memory, and disk I/O, causing timeouts or replication lag on shared environments.

  2. Create a dedicated sbtest database for benchmark tables.
    $ mysql --user=root --password --execute="CREATE DATABASE sbtest;"
    Enter password:

    On some MariaDB installs, local root logins use UNIX socket authentication, so sudo mysql can be required.

  3. Create a dedicated sbtest user scoped to the benchmark database.
    $ mysql --user=root --password --execute="CREATE USER 'sbtest'@'localhost' IDENTIFIED BY '<password>'; GRANT ALL PRIVILEGES ON sbtest.* TO 'sbtest'@'localhost'; FLUSH PRIVILEGES;"
    Enter password:

    For TCP connections, create the account as 'sbtest'@'127.0.0.1' or a specific client host instead of 'localhost'.

    Command-line passwords passed to sysbench can appear in process listings, so prefer a throwaway credential.

  4. Prepare the sysbench dataset with a table count and row count that reflect the target workload.
    $ sysbench --db-driver=mysql --mysql-host=localhost --mysql-user=sbtest --mysql-password='<password>' --mysql-db=sbtest --tables=2 --table-size=1000 oltp_read_write prepare
    sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
    
    Creating table 'sbtest1'...
    Inserting 1000 records into 'sbtest1'
    Creating a secondary index on 'sbtest1'...
    Creating table 'sbtest2'...
    Inserting 1000 records into 'sbtest2'
    Creating a secondary index on 'sbtest2'...

    Using localhost typically uses a UNIX socket on Linux; use 127.0.0.1 to force TCP.

    Large --tables and --table-size values consume disk quickly, so confirm free space before scaling up.

  5. Run the read/write workload for a fixed duration and thread count.
    $ sysbench --db-driver=mysql --mysql-host=localhost --mysql-user=sbtest --mysql-password='<password>' --mysql-db=sbtest --tables=2 --table-size=1000 --threads=4 --time=20 --report-interval=10 oltp_read_write run
    sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
    
    Running the test with following options:
    Number of threads: 4
    Report intermediate results every 10 second(s)
    Initializing random number generator from current time
    
    
    Initializing worker threads...
    
    Threads started!
    
    [ 10s ] thds: 4 tps: 892.68 qps: 17885.04 (r/w/o: 12524.08/3573.71/1787.25) lat (ms,95%): 6.79 err/s: 1.50 reconn/s: 0.00
    [ 20s ] thds: 4 tps: 860.21 qps: 17234.43 (r/w/o: 12068.59/3443.53/1722.31) lat (ms,95%): 7.04 err/s: 1.90 reconn/s: 0.00
    SQL statistics:
        queries performed:
            read:                            245952
            write:                           70185
            other:                           35102
            total:                           351239
        transactions:                        17534  (876.42 per sec.)
        queries:                             351239 (17556.26 per sec.)
        ignored errors:                      34     (1.70 per sec.)
        reconnects:                          0      (0.00 per sec.)
    General statistics:
        total time:                          20.0059s
        total number of events:              17534
    Latency (ms):
             min:                                    2.10
             avg:                                    4.56
             max:                                   53.43
             95th percentile:                        6.91
             sum:                                79996.85
    Threads fairness:
        events (avg/stddev):           4383.5000/7.16
        execution time (avg/stddev):   19.9992/0.00

    Compare transactions per second, 95th percentile latency, and error counts across runs and configurations.

  6. Repeat the benchmark run multiple times with identical parameters.

    Use the median of at least three runs for a steadier baseline.

  7. Remove the sysbench tables when measurements are complete.
    $ sysbench --db-driver=mysql --mysql-host=localhost --mysql-user=sbtest --mysql-password='<password>' --mysql-db=sbtest --tables=2 oltp_read_write cleanup
    sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
    
    Dropping table 'sbtest1'...
    Dropping table 'sbtest2'...
  8. Drop the benchmark database to reclaim disk space.
    $ mysql --user=root --password --execute="DROP DATABASE sbtest;"
    Enter password:
  9. Drop the benchmark user after cleanup.
    $ mysql --user=root --password --execute="DROP USER 'sbtest'@'localhost';"
    Enter password:

    If the account was created for TCP, drop the matching host entry (for example 'sbtest'@'127.0.0.1').

  10. Confirm the benchmark database no longer exists.
    $ mysql -vvv --user=root --password --execute="SHOW DATABASES LIKE 'sbtest';"
    Enter password:
    --------------
    SHOW DATABASES LIKE 'sbtest'
    --------------
    
    Empty set (0.00 sec)
    
    Bye