├── Dockerfile ├── README.md └── low-memory-my.cnf /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mysql/mysql-server 2 | 3 | COPY low-memory-my.cnf /etc/mysql/my.cnf 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Low memory MySQL 2 | 3 | MySQL is great, but with its default settings, it uses a lot of memory. This can be a problem when deploying it in a low-memory environment, such as a virtual server or a Docker container server. 4 | 5 | This project defines a Dockerfile which replaces the config file of the default MySQL Docker image with one which uses less memory. These modifications come from the following sources: 6 | 7 | * http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html 8 | * https://mariadb.com/de/node/579 9 | 10 | -------------------------------------------------------------------------------- /low-memory-my.cnf: -------------------------------------------------------------------------------- 1 | # For advice on how to change settings please see 2 | # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html 3 | 4 | [mysqld] 5 | # 6 | # Remove leading # and set to the amount of RAM for the most important data 7 | # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 8 | # innodb_buffer_pool_size = 128M 9 | # 10 | # Remove leading # to turn on a very important data integrity option: logging 11 | # changes to the binary log between backups. 12 | # log_bin 13 | # 14 | # Remove leading # to set options mainly useful for reporting servers. 15 | # The server defaults are faster for transactions and fast SELECTs. 16 | # Adjust sizes as needed, experiment to find the optimal values. 17 | # join_buffer_size = 128M 18 | # sort_buffer_size = 2M 19 | # read_rnd_buffer_size = 2M 20 | skip-host-cache 21 | skip-name-resolve 22 | datadir=/var/lib/mysql 23 | socket=/var/lib/mysql/mysql.sock 24 | secure-file-priv=/var/lib/mysql-files 25 | user=mysql 26 | 27 | # Disabling symbolic-links is recommended to prevent assorted security risks 28 | symbolic-links=0 29 | 30 | log-error=/var/log/mysqld.log 31 | pid-file=/var/run/mysqld/mysqld.pid 32 | 33 | 34 | #### These optimize the memory use of MySQL 35 | #### http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html 36 | innodb_buffer_pool_size=5M 37 | innodb_log_buffer_size=256K 38 | query_cache_size=0 39 | max_connections=10 40 | key_buffer_size=8 41 | thread_cache_size=0 42 | host_cache_size=0 43 | innodb_ft_cache_size=1600000 44 | innodb_ft_total_cache_size=32000000 45 | 46 | # per thread or per operation settings 47 | thread_stack=131072 48 | sort_buffer_size=32K 49 | read_buffer_size=8200 50 | read_rnd_buffer_size=8200 51 | max_heap_table_size=16K 52 | tmp_table_size=1K 53 | bulk_insert_buffer_size=0 54 | join_buffer_size=128 55 | net_buffer_length=1K 56 | innodb_sort_buffer_size=64K 57 | 58 | #settings that relate to the binary log (if enabled) 59 | binlog_cache_size=4K 60 | binlog_stmt_cache_size=4K 61 | 62 | #### from https://mariadb.com/de/node/579 63 | performance_schema = off 64 | 65 | --------------------------------------------------------------------------------