Variables: How MySQL Is Configured
Server settings are system variables. Read them with SHOW VARIABLES or SELECT @@name. Some can change at runtime with SET GLOBAL, but only the file my.cnf (or my.ini) makes a change survive a restart. MySQL 8 offers SET PERSIST to do both.
Result:
| Variable_name | Value |
|---|---|
| max_connections | 151 |
Result:
| mysql_8 | server_charset | server_collation | engine |
|---|---|---|---|
| 1 | utf8mb4 | utf8mb4_0900_ai_ci | InnoDB |
sql_mode: How Strict Is MySQL?
sql_mode controls how MySQL treats bad data and SQL syntax. The 8.0 default includes strict modes and ONLY_FULL_GROUP_BY:
Result:
| mode |
|---|
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
Strict mode makes an invalid value an error instead of a silent change. Compare:
ERROR 1264: Out of range value for column 'n' at row 1
Result:
| silently_changed_to |
|---|
| 127 |
Status: What Is Happening Now
SHOW STATUS counters describe the server's activity since start. Useful ones:
| Status variable | Meaning |
|---|---|
Threads_connected | Open connections |
Max_used_connections | Highest number reached (compare with max_connections) |
Questions / Uptime | Queries per second over time |
Slow_queries | Statements slower than long_query_time |
Innodb_buffer_pool_reads vs Innodb_buffer_pool_read_requests | Disk reads vs memory reads (hit ratio) |
Created_tmp_disk_tables | Temp tables spilled to disk |
Result:
| VARIABLE_NAME |
|---|
| Slow_queries |
| Threads_connected |
| Uptime |
Numbers change every second, so only the names are shown. Monitoring tools (Prometheus mysqld_exporter, Percona Monitoring and Management, CloudWatch) collect them over time.
The Settings That Matter Most
| Variable | Typical guidance |
|---|---|
innodb_buffer_pool_size | 50-70% of RAM on a dedicated server, the biggest performance lever |
max_connections | Enough for your pool size plus admin. More is not better: each connection uses memory |
innodb_flush_log_at_trx_commit | 1 for safety, 2 for speed with small risk |
innodb_log_file_size / innodb_redo_log_capacity | Large enough to absorb write bursts |
long_query_time and the slow log | Turn on, 0.5 to 1 second |
character_set_server | utf8mb4 |
Replication: Copies for Safety and Reads
Replication sends the primary server's binary log to one or more replicas that apply the same changes. Uses: failover, read scaling, running reports without loading the primary, and backups from a replica.
Replication is asynchronous by default, so a replica can lag. Your application must tolerate reading slightly old data from replicas, or read critical data from the primary. Semi-synchronous replication and Group Replication / InnoDB Cluster add stronger guarantees and automatic failover.
Scaling Options in Order
- Fix queries and indexes first. Most problems are here (previous lessons).
- Add memory and tune the buffer pool.
- Cache hot reads in the application or with Redis.
- Read replicas for read-heavy workloads.
- Partition large tables by range or hash to manage and prune data.
- Sharding (split data across servers by key) is a last resort, because it complicates queries and transactions. Managed or distributed options (Vitess, TiDB) exist.
Partitioning in One Example
Result:
| PARTITION_NAME | TABLE_ROWS |
|---|---|
| p2024 | 1 |
| p2025 | 2 |
| pmax | 0 |
Old partitions can be dropped instantly (ALTER TABLE sales DROP PARTITION p2024) instead of running a slow DELETE. The partition key must be part of every unique key.
Common Beginner Mistakes
| Mistake | What happens | Fix |
|---|---|---|
| Running the default tiny buffer pool in production | Constant disk reads | Size it for your data |
Turning off strict sql_mode to make an import "work" | Corrupted data | Fix the data |
max_connections = 5000 | Memory exhaustion | Use a connection pool |
| Reading from replicas right after a write | Stale data | Read from the primary when freshness matters |
| Sharding too early | Huge complexity | Index, cache, replicate, partition first |
Changing SET GLOBAL and forgetting my.cnf | Reverts after restart | SET PERSIST or edit the file |
Practice
- Read your server's
sql_modeand explain each flag. - Check
innodb_buffer_pool_sizeand compare with the machine's RAM. - Draw how a read replica fits into your app.
- Create a table partitioned by year and look at the partition list.
Conclusion
Read and tune variables carefully, keep strict sql_mode, watch status counters, size the InnoDB buffer pool, and scale in order: queries and indexes, memory, caching, replicas, partitioning and only then sharding.

