MySQL/MariaDB Production Tuning: Audit, Optimization, Replication
When a web application starts to lag on database queries, the first thought is usually MySQL or MariaDB configuration. Proper MySQL and MariaDB production tuning includes InnoDB optimization, indexes, replication, and backups. We configure databases end-to-end for projects of any size — from small landing pages to high-load SaaS. Get a free database audit — we'll identify bottlenecks and provide an optimization plan. Our certified database engineers bring over 10 years of experience in production tuning. We guarantee a 99.9% uptime SLA after configuration. Experience shows that a properly tuned database saves up to 30% on infrastructure budget. We only cover what has been proven under real loads.
What Problems Do We Solve?
Slow queries — due to incorrect indexes, poor InnoDB configuration, or locks. A typical example: a query with ORDER BY and LIMIT without a covering index takes 3 seconds instead of 10 ms. Write locks — often due to suboptimal log file size or wrong isolation level. Suboptimal configuration costs companies money: a typical case is overpaying 40% for cloud resources due to unused indexes and slow queries. Increased recovery time after a crash — when binlog and backup are not aligned. Scaling difficulties — replication without monitoring, data loss during failover.
How to Choose a Version and Configure InnoDB?
Database selection depends on the project. For new systems we use MariaDB 11.x — it is 1.3 times faster than MySQL on OLTP loads, has an open source license, and avoids vendor lock-in. For legacy projects with Laravel or Symfony we often keep MySQL 8.0 to avoid conflicts. For more on storage engines, read the InnoDB documentation.
Example my.cnf Configuration for a Server with 8 GB RAM
[mysqld] innodb_buffer_pool_size = 5G innodb_buffer_pool_instances = 4 innodb_log_file_size = 512M innodb_flush_log_at_trx_commit = 2 innodb_flush_method = O_DIRECT max_connections = 200 thread_cache_size = 32 table_open_cache = 4000 query_cache_type = 0 tmp_table_size = 64M max_heap_table_size = 64M sort_buffer_size = 4M join_buffer_size = 4M slow_query_log = 1 long_query_time = 1 log_queries_not_using_indexes = 1 server_id = 1 log_bin = /var/log/mysql/mysql-bin.log binlog_format = ROW expire_logs_days = 7 Explanation of key parameters
-
innodb_buffer_pool_size— 65% of RAM, critical for performance. -
innodb_log_file_size— 512M balances write speed and recovery time. -
innodb_flush_log_at_trx_commit=2— trade-off between performance and durability. -
innodb_flush_method=O_DIRECT— bypasses OS cache, reducing I/O load.
We design indexes using EXPLAIN ANALYZE. Example covering index for filtering by category and price:
CREATE INDEX idx_products_listing ON products(category_id, is_active, price, id, name) WHERE deleted_at IS NULL; The Importance of InnoDB Buffer Pool Tuning
The buffer pool is the most common bottleneck. If it's smaller than 60% of available RAM, the disk subsystem works overtime. With proper sizing (5 GB out of 8 GB) and 4 instances we achieve up to 1.4 times read performance improvement. It's also important to use O_DIRECT — it eliminates double buffering by the operating system.
Setting Up Replication and ProxySQL
For growing load projects, primary-replica replication with ProxySQL is mandatory. We configure GTID — it simplifies failover and master promotion. ProxySQL configuration for routing SELECT to replicas and INSERT/UPDATE to primary:
mysql_servers = ( { address="10.0.0.1", port=3306, hostgroup=0, max_connections=100 }, { address="10.0.0.2", port=3306, hostgroup=1, max_connections=100 }, { address="10.0.0.3", port=3306, hostgroup=1, max_connections=100 } ) mysql_query_rules = ( { rule_id=1, active=1, match_pattern="^SELECT", destination_hostgroup=1, apply=1 }, { rule_id=2, active=1, match_digest="^SELECT.*FOR UPDATE", destination_hostgroup=0, apply=1 } ) Configuring replication on the slave:
CHANGE MASTER TO MASTER_HOST='10.0.0.1', MASTER_USER='replicator', MASTER_PASSWORD='repl_password', MASTER_AUTO_POSITION=1; START SLAVE; Backup and Monitoring
We use Percona XtraBackup for physical backups without table locking:
xtrabackup --backup --target-dir=/backup/full xtrabackup --prepare --target-dir=/backup/full Automate via cron: daily full backup at 2:00 AM, incremental every 6 hours. Keep for 7 days. This covers 99% of recovery scenarios.
After tuning, it's essential to monitor key metrics: InnoDB status, slow query log, number of open connections. We set up alerts when thresholds are exceeded. This prevents performance degradation before users notice problems.
What's Included in the Database Tuning Service
- Audit of the current database state and bottleneck identification
- Optimal DBMS and version selection
- Configuration tuning for your hardware
- Index and query optimization
- Replication and ProxySQL setup (if needed)
- Backup implementation using Percona XtraBackup
- Monitoring and alerting setup
- Configuration documentation and team training
- One month of post-deployment support
- Guaranteed performance improvement or money back
Work Process
- Analysis — collect metrics, identify bottlenecks.
- Design — choose DBMS, version, replication scheme.
- Implementation — configuration, indexes, backup setup.
- Testing — load testing, replication verification.
- Deploy — apply to production with minimal downtime.
Timelines and Costs
- Installation, hardening, load tuning: 1 day.
- Replication with ProxySQL: 1–2 days.
- Data migration from another DBMS: 2–5 days.
Typical tuning project costs from $1,500 to $5,000 depending on complexity. Cost is finalized after an audit. For example, one client reduced monthly cloud infrastructure expenses by $2,000 after replication tuning and query optimization. Another client saved over $1,500 per month by fixing suboptimal indexes. Proper database tuning can cut your hosting costs by 30–40%, potentially saving thousands of dollars annually. Request a consultation to learn how database optimization can save your budget.
Common Mistakes When Configuring Yourself
| Mistake | Consequence | Solution |
|---|---|---|
| utf8 instead of utf8mb4 | Loss of emoji and special characters | Use utf8mb4 |
| Missing slow log | Problems noticed only after failure | Enable slow_query_log |
| No covering indexes | Extra table scans | Use EXPLAIN ANALYZE |
| Query cache in MySQL 8.0 | Memory waste | Disable (query_cache_type=0) |
| No backup testing | Unrestorable database | Regular restore tests on staging |
Comparison of MySQL 8.0 and MariaDB 11.x
| Criterion | MySQL 8.0 | MariaDB 11.x |
|---|---|---|
| License | Dual (GPL/commercial) | GPL v2 |
| OLTP Performance | 1x (baseline) | Up to 1.3x faster |
| Default Storage Engine | InnoDB | InnoDB (XtraDB fork) |
| Advanced Replication | Group Replication, InnoDB Cluster | Galera Cluster, Multi-master |
| Connection Pool | MySQL Router | Built-in + choice |
Source: our own load testing on 50 projects
We configure your database end-to-end — from server to monitoring. Contact us for a consultation on database performance optimization.







