brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: SET PERSIST changes a MySQL setting now and keeps it after restart

Mysql
~/tips/tip-mysql-set-persist

SET PERSIST max_connections = 300;

Applies a server setting immediately without editing a config file.

SET GLOBAL is quick, and forgotten at the next restart. Editing the config file lasts, but needs a restart. MySQL 8 has a statement that does both jobs.

Use PERSIST instead of GLOBAL:

SET PERSIST max_connections = 300;

The value takes effect at once and is written to mysqld-auto.cnf in the data directory, which the server reads at startup. For settings that can only be set at startup, there is a variant that stores without applying:

SET PERSIST_ONLY back_log = 1000;

To see what has been persisted, and to undo it:

SELECT * FROM performance_schema.persisted_variables;
RESET PERSIST max_connections;

RESET PERSIST removes the entry from the file but leaves the running value as it is, so set it back with SET GLOBAL too if you need that now. Without a name it removes every persisted setting.

The trap is a split brain between two places. Someone reads my.cnf, sees one value and the server uses another, because the persisted one is applied on top. I’d pick one method per server, and if it’s this one, look at that table first when a setting surprises you. Leave the JSON file itself alone; the manual says to manage it only through these statements. You also need the matching administrative privileges.

Further reading: Persisted system variables

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Mysql tips FOR UPDATE SKIP LOCKED; mysql_config_editor set --login-path=shop \ ALTER TABLE orders ADD COLUMN note VARCHAR(100), ALGORITHM=INSTANT; ALTER USER 'appuser'@'192.0.2.10' SELECT * FROM sys.schema_unused_indexes All Mysql tips (8) All topics

Link