MySQL Server Variables, Status, Replication and Scaling Overview

MySQL 60 min min read Updated: Nov 27, 2026 Advanced
MySQL Server Variables, Status, Replication and Scaling Overview
Advanced Topic 3 of 3

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.

sql SHOW VARIABLES LIKE 'max_connections';

Result:

Variable_nameValue
max_connections151
sql SELECT @@version >= '8.0' AS mysql_8, @@character_set_server AS server_charset, @@collation_server AS server_collation, @@default_storage_engine AS engine;

Result:

mysql_8server_charsetserver_collationengine
1utf8mb4utf8mb4_0900_ai_ciInnoDB
sql SET GLOBAL max_connections = 300; -- until restart SET PERSIST max_connections = 300; -- survives restart (stored in mysqld-auto.cnf) SET SESSION sql_mode = 'STRICT_ALL_TABLES'; -- this connection only

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:

sql SELECT @@sql_mode AS mode;

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:

sql CREATE TABLE t (n TINYINT); INSERT INTO t VALUES (500);
Strict (default)

ERROR 1264: Out of range value for column 'n' at row 1

sql CREATE TABLE t (n TINYINT); SET SESSION sql_mode = ''; INSERT INTO t VALUES (500); SELECT n AS silently_changed_to FROM t;

Result:

silently_changed_to
127
Never run production in non-strict mode The second result is the data corruption strict mode prevents: 500 became 127 without an error.

Status: What Is Happening Now

SHOW STATUS counters describe the server's activity since start. Useful ones:

Status variableMeaning
Threads_connectedOpen connections
Max_used_connectionsHighest number reached (compare with max_connections)
Questions / UptimeQueries per second over time
Slow_queriesStatements slower than long_query_time
Innodb_buffer_pool_reads vs Innodb_buffer_pool_read_requestsDisk reads vs memory reads (hit ratio)
Created_tmp_disk_tablesTemp tables spilled to disk
sql SELECT VARIABLE_NAME FROM performance_schema.global_status WHERE VARIABLE_NAME IN ('Threads_connected', 'Slow_queries', 'Uptime') ORDER BY VARIABLE_NAME;

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

VariableTypical guidance
innodb_buffer_pool_size50-70% of RAM on a dedicated server, the biggest performance lever
max_connectionsEnough for your pool size plus admin. More is not better: each connection uses memory
innodb_flush_log_at_trx_commit1 for safety, 2 for speed with small risk
innodb_log_file_size / innodb_redo_log_capacityLarge enough to absorb write bursts
long_query_time and the slow logTurn on, 0.5 to 1 second
character_set_serverutf8mb4

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.

text writes binary log app -----------> PRIMARY ----------------+----> REPLICA 1 (reads, reports) +----> REPLICA 2 (backup, standby)
sql -- on a replica (MySQL 8.0.23+ syntax); shown, not run CHANGE REPLICATION SOURCE TO SOURCE_HOST = 'primary.example.com', SOURCE_USER = 'repl', SOURCE_PASSWORD = '...', SOURCE_AUTO_POSITION = 1; START REPLICA; SHOW REPLICA STATUS\G -- check Replica_IO_Running, Replica_SQL_Running, Seconds_Behind_Source

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

  1. Fix queries and indexes first. Most problems are here (previous lessons).
  2. Add memory and tune the buffer pool.
  3. Cache hot reads in the application or with Redis.
  4. Read replicas for read-heavy workloads.
  5. Partition large tables by range or hash to manage and prune data.
  6. 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

sql CREATE TABLE sales (id INT NOT NULL, sold DATE NOT NULL, amount INT, PRIMARY KEY (id, sold)) PARTITION BY RANGE (YEAR(sold)) ( PARTITION p2024 VALUES LESS THAN (2025), PARTITION p2025 VALUES LESS THAN (2026), PARTITION pmax VALUES LESS THAN MAXVALUE ); INSERT INTO sales VALUES (1, '2024-05-01', 10), (2, '2025-02-01', 20), (3, '2025-08-01', 30); SELECT PARTITION_NAME, TABLE_ROWS FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'sales' ORDER BY PARTITION_ORDINAL_POSITION;

Result:

PARTITION_NAMETABLE_ROWS
p20241
p20252
pmax0

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

MistakeWhat happensFix
Running the default tiny buffer pool in productionConstant disk readsSize it for your data
Turning off strict sql_mode to make an import "work"Corrupted dataFix the data
max_connections = 5000Memory exhaustionUse a connection pool
Reading from replicas right after a writeStale dataRead from the primary when freshness matters
Sharding too earlyHuge complexityIndex, cache, replicate, partition first
Changing SET GLOBAL and forgetting my.cnfReverts after restartSET PERSIST or edit the file

Practice

  1. Read your server's sql_mode and explain each flag.
  2. Check innodb_buffer_pool_size and compare with the machine's RAM.
  3. Draw how a read replica fits into your app.
  4. 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.

Quick Summary: variables, sql_mode, status, buffer pool, replication, replicas, partitioning.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators