I have a fresh Laravel 8 installation together with mysql:8.0 image.
I want to add some configurations to MySql.
This is my mysql service in the docker-compose.yml
:
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
This works fine. If I now try to add a my.cnf
to the volumes like this:
volumes:
- 'sailmysql:/var/lib/mysql'
- './docker/8.0/my.cnf:/etc/mysql/my.cnf'
and reboot the container with sail down
and sail up
, then it suddenly fails with:
mysql_1 | 2021-11-06T13:26:52.465786Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
mysql_1 | 2021-11-06T13:26:52.465813Z 0 [ERROR] [MY-010119] [Server] Aborting
How can I include the configs?
The custom my.cnf
is overwriting settings (pid-file, socke and datadir) which causes the mysql service to fail. To not overwrite them, one needs to keep the original my.cnf
file which is:
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
So in your case you had to add:
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
innodb_io_capacity = 2000
innodb_read_io_threads = 64
innodb_thread_concurrency = 64
innodb_write_io_threads = 64
Just stumbled upon your question since i had the same problem. I am using Laravel with Sail with the current mysql docker container.
I inspected the docker container and the mysql configuration is saved like so:
The base my.cnf
file is located here:
/etc/my.cnf
(there is also a folder /etc/my.cnf.d/
, but putting a custom.cnf file there did not work, since it is not included inside /etc/my.cnf
)
What i did in my docker-compose.yml
file after i copied the original contents of /etc/my.cnf
from the docker container is:
volumes:
- 'sail-mysql:/var/lib/mysql'
- './docker/8.2/my.cnf:/etc/my.cnf'
I needed it since i got MySQL: Error Code: 1118 Row size too large (> 8126).
that may be fixed like that:
innodb_strict_mode = OFF
You can inspect the mysql docker configuration by loggin into the running container like that (see https://hub.docker.com/_/mysql ):
$ docker exec -it nameOfMysqlContainer bash
To list the files in the etc folder when logged in:
$ ls -la /etc/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.