Video Lesson: Increase the MySQL buffer pool size with a command or my.cnf in Docker

Increase the MySQL buffer pool size with a command or my.cnf in Docker

Learn how to configure database memory settings using startup commands or custom configuration files in Docker.


Lesson Content

There are two ways to increase the InnoDB buffer pool size in Docker. You can add the value directly to the database service command, or mount a custom MariaDB configuration file into the container.

The default buffer pool size is 128 MB. For this example, we’ll increase it to 256 MB.

The Docker Compose file already uses the database service’s command property to set the maximum allowed packet size. Add --innodb_buffer_pool_size=256M to that command:

services:
  db:
    command: --max_allowed_packet=64M --innodb_buffer_pool_size=256M

Keep any other existing properties in the db service unchanged. Save the file and restart the database service:

bin/restart db

The database starts with a 256 MB InnoDB buffer pool.

You can also keep this setting in a separate MariaDB configuration file. MariaDB reads its startup configuration from /etc/mysql/my.cnf, which includes configuration files in /etc/mysql/conf.d. Mount a custom file into that directory from the database service’s volumes list:

services:
  db:
    volumes:
      - dbdata:/var/lib/mysql
      - ./images/mysql/conf/my.cnf:/etc/mysql/conf.d/custom.cnf:cached

Create the local directory for the configuration file:

mkdir -p images/mysql/conf

Now create images/mysql/conf/my.cnf with the setting in the mysqld group:

[mysqld]
innodb_buffer_pool_size=256M

Save the file and restart the database service:

bin/restart db

When the service starts again, MariaDB loads custom.cnf from /etc/mysql/conf.d, and the buffer pool size is set to 256 MB. The command-line approach is convenient for a single value, while a custom configuration file gives you a place to keep additional MariaDB settings.

Maggie

Hey, I'm Maggie! 👋

Ask me anything.

Want to chat with Maggie?

Log in for AI tutor access.

Comments

Join the discussion!

Notes

Keep track of what you learn!