Mysql
什麼是停止 mysql docker 容器的安全方法?
我使用 Docker 執行 mysql 容器。我開始喜歡
sudo docker -d --name mysql -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql mysql_image
我懷疑通過停止 docker 來停止 mysql 是不安全的。我錯了嗎?
sudo docker stop mysql
首先在容器內停止mysql是否更安全?
sudo docker exec mysql /usr/bin/mysqladmin shutdown
看起來很安全,來自文件:
容器內的主程序將收到 SIGTERM,並在寬限期後收到 SIGKILL。
因此,如果主程序是 mysqld,它將有一個不錯的機會刷新所有內容。
似乎在不關閉 MySQL 的情況下停止 docker 容器會創建損壞的 MySQL 數據量。因此,有必要在停止容器之前執行 MySQL 關閉,以便 MySQL 將所有更改刷新到磁碟。
這是在卷上啟動 mysql 的日誌,從容器創建,由 docker 停止。注意 XA 崩潰恢復步驟是否存在。
2021-05-18 06:34:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started. 2021-05-18 06:34:54+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2021-05-18 06:34:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started. 2021-05-18T06:34:54.844455Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.25) starting as process 1 2021-05-18T06:34:54.887402Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-05-18T06:35:00.523370Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2021-05-18T06:35:11.094092Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock 2021-05-18T06:35:11.181732Z 0 [System] [MY-010229] [Server] Starting XA crash recovery... 2021-05-18T06:35:11.198947Z 0 [System] [MY-010232] [Server] XA crash recovery finished. 2021-05-18T06:35:11.375917Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2021-05-18T06:35:11.376529Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2021-05-18T06:35:11.397202Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. 2021-05-18T06:35:11.628776Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.25' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
使用時
docker exec tu-live-db /usr/bin/mysqladmin -uroot -proot shutdown
在殺死一個容器之前,XA 崩潰恢復沒有啟動,並且數據量對於下一個容器啟動是有效的
2021-05-18 06:36:44+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started. 2021-05-18 06:36:47+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2021-05-18 06:36:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started. 2021-05-18T06:36:48.040045Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.25) starting as process 1 2021-05-18T06:36:48.082740Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-05-18T06:36:53.426493Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2021-05-18T06:36:57.611953Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock 2021-05-18T06:36:57.827561Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2021-05-18T06:36:57.828060Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2021-05-18T06:36:57.845291Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. 2021-05-18T06:36:58.014550Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.25' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.