为什么 MariaDB 加载设置大约 5-8 分钟?



我想使用 docker-compose 创建两个图像: 1. 我的弹簧启动应用程序 2. MariaDB 作为应用程序的数据库

MariaDB 的 dockerfile :

FROM mariadb:latest
ADD my.cnf /etc/mysql/my.cnf
ENV MYSQL_USER test
ENV MYSQL_PASSWORD Test123456
ENV MYSQL_ROOT_PASSWORD lsagvcbjkz<kcnz
EXPOSE 3306

和 docker.compose:

version: '2.1'
services:
db:
image: mariadb
container_name: mariaDB
environment:
MYSQL_DATABASE: testdb
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
networks:
- backend
app:
image: app
container_name: APP
restart: on-failure
ports:
- 8080:8080
depends_on:
db:
condition: service_healthy
networks:
- backend
networks:
backend:
driver: bridge

MariaDB 日志:

Initializing database

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h  password 'new-password'
Alternatively you can run:
'/usr/bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
Database initialized
MySQL init process in progress...
2019-10-01  9:08:58 0 [Note] mysqld (mysqld 10.4.8-MariaDB-1:10.4.8+maria~bionic) starting as process 108 ...
2019-10-01  9:08:58 0 [Note] InnoDB: Using Linux native AIO
2019-10-01  9:08:59 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-10-01  9:08:59 0 [Note] InnoDB: Uses event mutexes
2019-10-01  9:08:59 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-10-01  9:08:59 0 [Note] InnoDB: Number of pools: 1
2019-10-01  9:08:59 0 [Note] InnoDB: Using SSE2 crc32 instructions
2019-10-01  9:08:59 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2019-10-01  9:08:59 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2019-10-01  9:08:59 0 [Note] InnoDB: Completed initialization of buffer pool
2019-10-01  9:08:59 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-10-01  9:08:59 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2019-10-01  9:08:59 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-10-01  9:08:59 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-10-01  9:08:59 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-10-01  9:08:59 0 [Note] InnoDB: 10.4.8 started; log sequence number 139836; transaction id 21
2019-10-01  9:08:59 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-10-01  9:08:59 0 [Note] Plugin 'FEEDBACK' is disabled.
2019-10-01  9:08:59 0 [Warning] 'user' entry 'root@c147913c7f5c' ignored in --skip-name-resolve mode.
2019-10-01  9:08:59 0 [Warning] 'user' entry '@c147913c7f5c' ignored in --skip-name-resolve mode.
2019-10-01  9:08:59 0 [Warning] 'proxies_priv' entry '@% root@c147913c7f5c' ignored in --skip-name-resolve mode.
2019-10-01  9:08:59 0 [Note] InnoDB: Buffer pool(s) load completed at 191001  9:08:59
2019-10-01  9:08:59 0 [Note] Reading of all Master_info entries succeeded
2019-10-01  9:08:59 0 [Note] Added new Master_info '' to hash table
2019-10-01  9:08:59 0 [Note] mysqld: ready for connections.
Version: '10.4.8-MariaDB-1:10.4.8+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  mariadb.org binary distribution
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
2019-10-01  9:16:52 25 [Warning] 'proxies_priv' entry '@% root@c147913c7f5c' ignored in --skip-name-resolve mode.

如您所见,MariaDB 不加载 my.cnf 文件:"端口:0 " 几分钟后,MariaDB 重置:

2019-10-01  9:16:52 0 [Note] mysqld (initiated by: unknown): Normal shutdown
2019-10-01  9:16:52 0 [Note] Event Scheduler: Purging the queue. 0 events
2019-10-01  9:16:52 0 [Note] InnoDB: FTS optimize thread exiting.
2019-10-01  9:16:52 0 [Note] InnoDB: Starting shutdown...
2019-10-01  9:16:52 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2019-10-01  9:16:52 0 [Note] InnoDB: Buffer pool(s) dump completed at 191001  9:16:52
2019-10-01  9:16:54 0 [Note] InnoDB: Shutdown completed; log sequence number 20431569; transaction id 14896
2019-10-01  9:16:54 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-10-01  9:16:54 0 [Note] mysqld: Shutdown complete

MySQL init process done. Ready for start up.
2019-10-01  9:16:54 0 [Note] mysqld (mysqld 10.4.8-MariaDB-1:10.4.8+maria~bionic) starting as process 1 ...
2019-10-01  9:16:54 0 [Note] InnoDB: Using Linux native AIO
2019-10-01  9:16:54 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-10-01  9:16:54 0 [Note] InnoDB: Uses event mutexes
2019-10-01  9:16:54 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-10-01  9:16:54 0 [Note] InnoDB: Number of pools: 1
2019-10-01  9:16:54 0 [Note] InnoDB: Using SSE2 crc32 instructions
2019-10-01  9:16:54 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2019-10-01  9:16:54 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2019-10-01  9:16:54 0 [Note] InnoDB: Completed initialization of buffer pool
2019-10-01  9:16:54 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-10-01  9:16:54 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2019-10-01  9:16:54 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-10-01  9:16:54 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-10-01  9:16:54 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-10-01  9:16:54 0 [Note] InnoDB: Waiting for purge to start
2019-10-01  9:16:54 0 [Note] InnoDB: 10.4.8 started; log sequence number 20431569; transaction id 14896
2019-10-01  9:16:54 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-10-01  9:16:54 0 [Note] Plugin 'FEEDBACK' is disabled.
2019-10-01  9:16:54 0 [Note] Server socket created on IP: '0.0.0.0'.
2019-10-01  9:16:54 0 [Warning] 'proxies_priv' entry '@% root@c147913c7f5c' ignored in --skip-name-resolve mode.
2019-10-01  9:16:54 0 [Note] Reading of all Master_info entries succeeded
2019-10-01  9:16:54 0 [Note] Added new Master_info '' to hash table
2019-10-01  9:16:54 0 [Note] mysqld: ready for connections.
Version: '10.4.8-MariaDB-1:10.4.8+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
2019-10-01  9:16:54 0 [Note] InnoDB: Buffer pool(s) load completed at 191001  9:16:54

从这一刻起,我的应用程序可以安全地连接到数据库。"端口:3306">

我的问题是: MariaDB 应该加载这么长时间吗? MariaDB 应该在加载 my.cnf 设置几分钟后休息吗?

mariadb docker 映像的入口点运行脚本docker-entrypoint.sh。此脚本将时区信息加载到运行以下命令的数据库中:

mysql_tzinfo_to_sql /usr/share/zoneinfo

在我的测试过程中,我看到运行此命令的时间可能非常高。设置环境变量MYSQL_INITDB_SKIP_TZINFO=1跳过此步骤并加快数据库初始化速度。

我遇到了同样的问题。似乎加载时区信息(有时(会占用大量时间(+6分钟(。

您可以通过禁用它来检查这一点:

db:
image: mariadb
environment:
- MYSQL_INITDB_SKIP_TZINFO=1

现在它开始不到 30 秒。

最新更新