Home / Configs / Servers / MySQL my.cnf settings

MySQL my.cnf settings: connections, buffer pool and slow query log

A small MySQL or MariaDB override file for connections, memory, character set and the slow query log.

For MySQL 8 or MariaDB 10 on Linux. The log path and service name can differ by distribution.

This file overrides a few MySQL settings without touching the main config. Set the number of connections, the memory for InnoDB and the logging you want, then restart MySQL.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

The default is 151
A common start is about half of the RAM on a database-only server. Use G or M

/etc/mysql/conf.d/custom.cnf
[mysqld]
max_connections = 200
innodb_buffer_pool_size = 1G
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
bind-address = 127.0.0.1

[client]
default-character-set = utf8mb4

How this setup works

Diagram: custom.cnf, then MySQL restarts, then New settings
custom.cnf (your overrides) → MySQL restarts (reads the file) → New settings (apply to all databases)

Step-by-step setup

  1. Save the settings above as /etc/mysql/conf.d/custom.cnf. On some systems the folder is /etc/my.cnf.d/.
  2. If you turned on the slow log, create its folder: sudo mkdir -p /var/log/mysql && sudo chown mysql:mysql /var/log/mysql.
  3. Restart MySQL: sudo systemctl restart mysql (the service may be called mysqld or mariadb).
  4. Check a value: mysql -e "SHOW VARIABLES LIKE 'max_connections'".
  5. Read slow queries with sudo tail /var/log/mysql/slow.log.

What the important lines mean

Common errors and how to fix them

ERROR 1040: Too many connections
The limit was reached. Raise max_connections, but first find out why: a script that never closes connections, or too many app workers. SHOW PROCESSLIST shows who is connected.
MySQL will not start after editing
A wrong value or a typo. Read the log with sudo journalctl -u mysql -n 50. A buffer pool larger than the free RAM is a common cause.
Slow log file is not created
The folder does not exist or is not owned by the mysql user. Create it and fix the owner, then restart.
Unknown variable
The name is wrong or not supported by your version. MariaDB and MySQL differ in a few settings.

Frequently asked questions

Where is my.cnf?
Run mysql --help and look for "Default options are read from the following files". Files in conf.d are read too, which is the safe place for your changes.
What should the buffer pool size be?
On a server that only runs MySQL, about half to two thirds of the RAM. On a shared small server use much less, so other programs still have memory.
Is it safe to set bind-address to 0.0.0.0?
Only with a firewall and strong passwords. Prefer 127.0.0.1 and an SSH tunnel, or allow only specific IP addresses.

Written for: MySQL 8.x and MariaDB 10.x options · Updated 2026-10-11

Free tools that help

Fix a problem with this setup

More server configs

See all 41 config generators