# Mysql container really high memory usage

**URL:** <https://forums.docker.com/t/mysql-container-really-high-memory-usage/77127>\
**Category:** General\
**Created:** [June 27, 2019, 4:12pm UTC](https://forums.docker.com/t/mysql-container-really-high-memory-usage/77127 "2019-06-27T16:12:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hnioche](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hnioche/32/24168_2.png) [@hnioche](https://forums.docker.com/u/hnioche)\
**Post date:** [June 27, 2019, 4:12pm UTC](https://forums.docker.com/t/mysql-container-really-high-memory-usage/77127/1 "2019-06-27T16:12:15Z")

</div>

Hi,  
I’m using docker for a development environment which has a mysql image.  
On my current computer, running arch linux up to date with the no chagne to the docker setup, everything is working fine but mysql that uses all the memory available.  
Each time I start the container, it uses immediately all the memory of my computer.  
Even the most basic use of the docker image with no database uses 16GB.

All the other containers runs fine with no issue

I’ve tried the docker library mysql image, version 8 and 5.7, the oracle version, the percona version, they all have the same issue.  
I’ve tried mariadb and it works as it’s supposed, using 100 something MB.  
I’ve tried the same mysql image with podman and had no issue, it uses around 200 MB.

My version of docker is:

```auto
Docker version 18.09.6-ce, build 481bc77156

```

Here’s the Dockerfile

```auto
FROM mysql:5.7
ENV MYSQL_ROOT_PASSWORD rootpassword
ENV MYSQL_ALLOW_EMPTY_PASSWORD=yes
ENV MYSQL_DATABASE=database

```

Here’s `docker stats`

```auto
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d66ccdbd03aa boring_haibt 0.20% 14.27GiB / 15.51GiB 92.00% 1.34kB / 0B 439MB / 299MB 27

```

And top inside the container

```auto
top - 16:11:06 up 7:32, 0 users, load average: 0.84, 2.05, 1.42
Tasks: 2 total, 1 running, 1 sleeping, 0 stopped, 0 zombie
%Cpu(s): 5.4 us, 3.0 sy, 0.2 ni, 87.1 id, 3.3 wa, 0.9 hi, 0.2 si, 0.0 st
KiB Mem: 16262332 total, 16100992 used, 161340 free, 10252 buffers
KiB Swap: 8388604 total, 6197880 used, 2190724 free. 443820 cached Mem

  PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    1 mysql 20 0 17.005g 0.013t 0 S 0.0 85.0 0:05.59 mysqld
  172 root 20 0 24152 2336 2000 R 0.0 0.0 0:00.15 top

```

I have no clue where the issue is coming from, does any one have an idea how I can troubleshoot that?

Edit:  
I tried to limit the memory usage of the container using `-m` and mysqld refuses to start when it is bellow 10g with the error:

```auto
ERROR: mysqld failed while attempting to check config
command was: "mysqld --verbose --help"

```

Edit 2:  
I found something even weirder.  
On the same machine, I run a Windows virtual machine using qemu-kvm.  
When this machine is started, the mysql container behave normally. When this machine is not started, it use all the memory of my computer

---

<div class="post-metadata">

**Author:** ![beldeveloper](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/beldeveloper/32/31633_2.png) [@beldeveloper](https://forums.docker.com/u/beldeveloper)\
**Post date:** [October 23, 2021, 1:20pm UTC](https://forums.docker.com/t/mysql-container-really-high-memory-usage/77127/2 "2021-10-23T13:20:41Z")

</div>

Hi,  
Did you solve the issue? Perhaps, you can recall a solution. I have exactly the same issue on Manjaro, meanwhile, at the same machine I have Ubuntu and it runs the same MySQL image like a charm.

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [October 23, 2021, 7:52pm UTC](https://forums.docker.com/t/mysql-container-really-high-memory-usage/77127/3 "2021-10-23T19:52:19Z")

</div>

It seems he has found the solution 🙂 [https://github.com/docker-library/mysql/issues/579#issuecomment-519495808](https://github.com/docker-library/mysql/issues/579#issuecomment-519495808)

---

<div class="post-metadata">

**Author:** ![beldeveloper](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/beldeveloper/32/31633_2.png) [@beldeveloper](https://forums.docker.com/u/beldeveloper)\
**Post date:** [October 24, 2021, 1:02pm UTC](https://forums.docker.com/t/mysql-container-really-high-memory-usage/77127/4 "2021-10-24T13:02:13Z")

</div>

Fantastic, thank you!

---

<div class="post-metadata">

**Author:** ![ragnarok22](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/ragnarok22/32/52965_2.png) [@ragnarok22](https://forums.docker.com/u/ragnarok22)\
**Post date:** [October 24, 2024, 12:28pm UTC](https://forums.docker.com/t/mysql-container-really-high-memory-usage/77127/5 "2024-10-24T12:28:28Z")

</div>

Using mysql:5.6 has the same issue.

Here the solution mentioned on [github](https://github.com/docker-library/mysql/issues/579#issuecomment-519495808):

> By default, on arch, the value is too low I guess.  
> running the container with `--ulimit nofile=262144:262144` solve the issue and mysql behaves normally

Also you can set ulimit using compose:

```auto
services:
  db:
    image: mysql:9
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    ports:
      - 3306:3306
    ulimits:
      nofile:
        soft: 262144
        hard: 262144

```

BTW, mysql:9 already have a limit so there’s no need to write the ulimits manually.
