#### 2.5.6.2 使用 Docker 部署 MySQL 服務器的更多主題
> **注意**
>
> 當必須指定 `mysql/mysql-server` 作為 Docker 鏡像存儲時, 下面的大多數命令都會使用它(像是 `docker pull` 和 `docker run` 命令); 如果你的鏡像來自另一個庫, 那就去修改—例如, 替換為 `store/oracle/mysql-enterprise-server` 是 Docker 商店的 MySQL 企業版鏡像, 或者 `container-registry.oracle.com/mysql/enterprise-server` 是 Oracle 容器庫的 MySQL 企業版鏡像.
##### 優化過的 Docker 版 MySQL 安裝
Docker 版 MySQL 鏡像進行了代碼優化, 這意味著他們只包含大多數在 Docker 容器中運行 MySQL 實例的與用戶相關的關鍵組件. MySQL Docker 安裝與常見的非 Docker 安裝的不同在以下幾個方面:
- 包含的二進制文件僅限于:
- `/usr/bin/my_print_defaults`
- `/usr/bin/mysql`
- `/usr/bin/mysql_config`
- `/usr/bin/mysql_install_db`
- `/usr/bin/mysql_tzinfo_to_sql`
- `/usr/bin/mysql_upgrade`
- `/usr/bin/mysqladmin`
- `/usr/bin/mysqlcheck`
- `/usr/bin/mysqldump`
- `/usr/bin/mysqlpump`
- `/usr/bin/mysqlbackup` (僅適用于 MySQL 8.0 企業版)
- `/usr/sbin/mysqld`
- 所有的二進制文件都會被刪除; 它們不包含調試信息.
##### 配置 MySQL 服務器
當你啟動 MySQL Docker 容器時, 你可以通過 `docker run` 命令將配置選項傳遞給服務器; 例如:
```bash
docker run --name mysql1 -d mysql/mysql-server:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_col
```
命令使用 `utf8mb4` 作為默認字符集, 使用 `utf8mb4_col` 作為數據庫的默認排序規則啟動 MySQL 服務器.
配置 MySQL 服務器的另外一種方式是準備一個配置文件, 將其掛載到容器內服務器配置文件的位置. 參閱[持久化數據和配置更改](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-persisting-data-configuration)獲取詳情.
##### 持久化數據和配置更改
Docker 容器原則上是短暫的, 如果容器被刪除或者損壞了, 任何數據或者配置都有可能會丟失([這里](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/)查看討論). [Docker volumes](https://docs.docker.com/engine/admin/volumes/volumes/), 然而, 提供了一種機制來保護 Docker 容器內創建的數據. 在初始化時, MySQL 服務器容器為服務器數據目錄創建一個 Docker volume. 在容器上運行 `docker inspect` 命令的 JSON 輸出中有一個 `Mount` 鍵, 其值提供了關于數據目錄卷(volume) 的相關信息:
```bash
shell> docker inspect mysql1
...
"Mounts": [
{
"Type": "volume",
"Name": "4f2d463cfc4bdd4baebcb098c97d7da3337195ed2c6572bc0b89f7e845d27652",
"Source": "/var/lib/docker/volumes/4f2d463cfc4bdd4baebcb098c97d7da3337195ed2c6572bc0b89f7e845d27652/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
...
```
輸出顯示源文件夾 `/var/lib/docker/volumes/4f2d463cfc4bdd4baebcb098c97d7da3337195ed2c6572bc0b89f7e845d27652/_data`, 已經掛載到 `/var/lib/mysql`, 即容器內的服務器數據目錄.
保存數據的另一種方式時在創建容器時使用 —— `--mount` 選項 [bind-mount](https://docs.docker.com/engine/reference/commandline/service_create/#add-bind-mounts-volumes-or-memory-filesystems) 主機目錄. 可以使用相同的技術來保存服務器的配置. 下面的命令創建一個 MySQL Server 容器并綁定掛載數據目錄和服務器配置文件:
```bash
docker run --name=mysql1 \
--mount type=bind,src=/path-on-host-machine/my.cnf,dst=/etc/my.cnf \
--mount type=bind,src=/path-on-host-machine/datadir,dst=/var/lib/mysql \
-d mysql/mysql-server:tag
```
命令掛載 `path-on-host-machine/my.cnf` 到 `/etc/my.cnf` (容器內的服務器配置文件), 并且掛載 `path-on-host-machine/datadir` 到 `/var/lib/mysql` (容器內的數據目錄). 必須滿足以下條件, 才能綁定掛載工作:
- 配置文件 `path-on-host-machine/my.cnf` 必須總是存在, 它必須包含啟動服務器的指定用戶 `mysql`:
```ini
[mysqld]
user=mysql
```
你也可以在文件中加載其他服務器配置項.
- 數據目錄 `path-on-host-machine/datadir` 必須已存在. 要對服務器進行初始化, 目錄必須為空. 可以掛載填充了數據的目錄, 并使用它啟動服務器; 然而, you must make sure you start the Docker container with the same configuration as the server that created the data, and any host files or directories required are mounted when starting the container.
##### 運行其他初始化腳本
如果在數據庫創建后, 有任何 `.sh` 或者 `.sql` 腳本希望立即在數據庫上運行, 你可以將它們放入到主機目錄內, 然后將目錄掛載到容器內的 `/docker-entrypoint-initdb.d/` 目錄. 例如:
```bash
docker run --name=mysql1 \
--mount type=bind,src=/path-on-host-machine/scripts/,dst=/docker-entrypoint-initdb.d/ \
-d mysql/mysql-server:tag
```
##### 從另外一個 Docker 容器中的應用連接到 MySQL
通過設置 Docker 網絡, 你可以允許多個 Docker 容器之間互相通信, 因此另外一個 Docker 容器中的客戶端應用可以訪問服務器容器中的 MySQL Server. 首先, 創建 Docker 網絡:
```bash
docker network create my-custom-net
```
然后, 當你創建和啟動服務器和客戶端容器時, use the `--network` option to put them on network you created. 例如:
```bash
docker run --name=mysql1 --network=my-custom-net -d mysql/mysql-server
```
```bash
docker run --name=myapp1 --network=my-custom-net -d myapp
```
`myapp1` 容器可以使用 `mysql1` 主機名連接到 `mysql1`容器, 反之亦然, Docker 會自動為給定的容器名稱設置 DNS. 在下面的示例中, 我們運行 `myapp1` 容器中的 [`mysql`](https://dev.mysql.com/doc/refman/8.0/en/mysql.html) 客戶端連接到 `mysql1` 主機所在的容器:
```bash
docker exec -it myapp1 mysql --host=mysql1 --user=myuser --password
```
關于容器的其他網絡技術, 參閱 Docker 文檔中的 [Docker 容器網絡](https://docs.docker.com/engine/userguide/networking/).
##### 服務器錯誤日志
當 MySQL Server 首次使用你的服務器容器啟動時, 如果滿足以下任何一個條件, 則不會生成[服務器錯誤日志](https://dev.mysql.com/doc/refman/8.0/en/error-log.html):
- 主機中已掛載服務器配置文件, 但是文件不包含系統變量 [`log_error`](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_log_error) (關于 bind-mounting 服務器配置文件參閱 [持久化數據和配置更改](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-persisting-data-configuration)).
- 主機并沒有掛載服務器配置文件, 但是 Docker 環境變量 [`MYSQL_LOG_CONSOLE`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-log-console) 為 true (MySQL 8.0 服務器容器的變量默認狀態). MySQL Server 的錯誤日志會重定向到 `stderr`, 因此錯誤日志進入到 Docker 容器日志并且可以使用 `docker logs mysqld-container` 命令查看.
To make MySQL Server generate an error log when either of the two conditions is true, use the [`--log-error`](https://dev.mysql.com/doc/refman/8.0/en/server-options.html#option_mysqld_log-error) option to [configure the server](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-configuring-server) to generate the error log at a specific location inside the container. To persist the error log, mount a host file at the location of the error log inside the container as explained in [Persisting Data and Configuration Changes](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-persisting-data-configuration). 然而, you must make sure your MySQL Server inside its container has write access to the mounted host file.
##### 使用 Docker MySQL 企業版備份
[MySQL Enterprise Backup](https://dev.mysql.com/doc/mysql-enterprise-backup/8.0/en/) is a commercially-licensed backup utility for MySQL Server, available with [MySQL Enterprise Edition](https://www.mysql.com/products/enterprise/). MySQL Enterprise Backup is included in the Docker installation of MySQL Enterprise Edition.
在下面的示例中, 我們假設你已經在 Docker 容器中運行了 MySQL Server (關于如何在 Docker 中啟動一個 MySQL Server, 參閱 [2.5.6.1 使用 Docker 部署 MySQL 服務器的基本步驟”](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-getting-started.html)). For MySQL Enterprise Backup to back up the MySQL Server, it must have access to the server's data directory. 可以通過以下方式實現, 例如, [bind-mounting a host directory on the data directory of the MySQL Server](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-persisting-data-configuration) when you start the server:
```bash
docker run --name=mysqlserver \
--mount type=bind,src=/path-on-host-machine/datadir/,dst=/var/lib/mysql \
-d store/oracle/mysql-enterprise-server:8.0
```
With this command, the MySQL Server is started with a Docker image of the MySQL Enterprise Edition, and the host directory `/path-on-host-machine/datadir/` has been mounted onto the server's data directory (`/var/lib/mysql`) inside the server container. We also assume that, after the server has been started, the required privileges have also been set up for MySQL Enterprise Backup to access the server (see [Grant MySQL Privileges to Backup Administrator](https://dev.mysql.com/doc/mysql-enterprise-backup/8.0/en/mysqlbackup.privileges.html) for details). Use the following steps then to backup and restore a MySQL Server instance.
**To backup a MySQL Server instance running in a Docker container using MySQL Enterprise Backup with Docker:**
1. On the same host where the MySQL Server container is running, start another container with an image of MySQL Enterprise Edition to perform a back up with the MySQL Enterprise Backup command [`backup-to-image`](https://dev.mysql.com/doc/mysql-enterprise-backup/8.0/en/backup-commands-backup.html#option_meb_backup-to-image). Provide access to the server's data directory using the bind mount we created in the last step. Also, mount a host directory (`/path-on-host-machine/backups/` in this example) onto the storage folder for backups in the container (`/data/backups` in the example) to persist the backups we are creating. 下面是這個步驟的示例命令:
```bash
shell> docker run \
--mount type=bind,src=/path-on-host-machine/datadir/,dst=/var/lib/mysql \
--mount type=bind,src=/path-on-host-machine/backups/,dst=/data/backups \
--rm store/oracle/mysql-enterprise-server:8.0 \
mysqlbackup -umysqlbackup -ppassword --backup-dir=/tmp/backup-tmp --with-timestamp \
--backup-image=/data/backups/db.mbi backup-to-image
[Entrypoint] MySQL Docker Image 8.0.11-1.1.5
MySQL Enterprise Backup version 8.0.11 Linux-4.1.12-61.1.16.el7uek.x86_64-x86_64 [2018-04-08 07:06:45]
Copyright (c) 2003, 2018, Oracle and/or its affiliates. All Rights Reserved.
180921 17:27:25 MAIN INFO: A thread created with Id '140594390935680'
180921 17:27:25 MAIN INFO: Starting with following command line ...
...
-------------------------------------------------------------
Parameters Summary
-------------------------------------------------------------
Start LSN : 29615616
End LSN : 29651854
-------------------------------------------------------------
mysqlbackup completed OK!
```
It is important to check the end of the output by **mysqlbackup** to make sure the backup has been completed successfully.
2. The container exits once the backup job is finished and, with the `--rm` option used to start it, it is removed after it exits. An image backup has been created, and can be found in the host directory mounted in the last step for storing backups:
```bash
shell> ls /tmp/backups
db.mbi
```
**To restore a MySQL Server instance in a Docker container using MySQL Enterprise Backup with Docker:**
1. 停止 MySQL 服務器容器, 這也會停止在內部運行的 MySQL 服務器:
```bash
docker stop mysqlserver
```
2. On the host, delete all contents in the bind mount for the MySQL Server data directory:
```bash
rm -rf /path-on-host-machine/datadir/*
```
3. Start a container with an image of MySQL Enterprise Edition to perform the restore with the MySQL Enterprise Backup command [`copy-back-and-apply-log`](https://dev.mysql.com/doc/mysql-enterprise-backup/8.0/en/backup-commands-restore.html#option_meb_copy-back-and-apply-log). Bind-mount the server's data directory and the storage folder for the backups, like what we did when we backed up the server:
```bash
shell> docker run \
--mount type=bind,src=/path-on-host-machine/datadir/,dst=/var/lib/mysql \
--mount type=bind,src=/path-on-host-machine/backups/,dst=/data/backups \
--rm store/oracle/mysql-enterprise-server:8.0 \
mysqlbackup --backup-dir=/tmp/backup-tmp --with-timestamp \
--datadir=/var/lib/mysql --backup-image=/data/backups/db.mbi copy-back-and-apply-log
[Entrypoint] MySQL Docker Image 8.0.11-1.1.5
MySQL Enterprise Backup version 8.0.11 Linux-4.1.12-61.1.16.el7uek.x86_64-x86_64 [2018-04-08 07:06:45]
Copyright (c) 2003, 2018, Oracle and/or its affiliates. All Rights Reserved.
180921 22:06:52 MAIN INFO: A thread created with Id '139768047519872'
180921 22:06:52 MAIN INFO: Starting with following command line ...
...
180921 22:06:52 PCR1 INFO: We were able to parse ibbackup_logfile up to
lsn 29680612.
180921 22:06:52 PCR1 INFO: Last MySQL binlog file position 0 155, file name binlog.000003
180921 22:06:52 PCR1 INFO: The first data file is '/var/lib/mysql/ibdata1'
and the new created log files are at '/var/lib/mysql'
180921 22:06:52 MAIN INFO: No Keyring file to process.
180921 22:06:52 MAIN INFO: Apply-log operation completed successfully.
180921 22:06:52 MAIN INFO: Full Backup has been restored successfully.
mysqlbackup completed OK! with 3 warnings
```
The container exits once the backup job is finished and, with the `--rm` option used when starting it, it is removed after it exits.
4. Restart the server container, which also restarts the restored server:
```bash
docker restart mysqlserver
```
Or, start a new MySQL Server on the restored data directory:
```bash
docker run --name=mysqlserver2 \
--mount type=bind,src=/path-on-host-machine/datadir/,dst=/var/lib/mysql \
-d store/oracle/mysql-enterprise-server:8.0
```
Log on to the server to check that the server is running with the restored data.
##### Docker 環境變量
當你創建 MySQL 服務器容器時, 你可以使用 `--env` 選項 (`-e`) 并指定一個或者多個下列的環境變量來配置 MySQL 實例.
> **注意**
>
> - 如果你掛載的數據目錄不是空的, 那么下列的變量都不會有效果, 因為服務器沒有嘗試初始化它們(參閱[持久化數據和配置更改](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-persisting-data-configuration)獲取詳情). 在容器啟動時, 文件夾中任何預先存在的內容, 包括任何舊的服務器配置, 都不會被修改.
> - bool 變量包含 [`MYSQL_RANDOM_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_random_root_password), [`MYSQL_ONETIME_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_onetime_password), [`MYSQL_ALLOW_EMPTY_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password), 和 [`MYSQL_LOG_CONSOLE`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-log-console) 通過設置一些非0長度的字符串來設置為 true. 因此, 設置它們為如 “0”, “false”, 或者 “no” 并不能使它們為 false, 但實際上讓他們為 true. 這對于 MySQL 服務器容器來說是一個已知的問題.
- [`MYSQL_RANDOM_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_random_root_password): 為 true 時(這是它的默認狀態, 除非 [`MYSQL_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-root-password) 被設置或者 [`MYSQL_ALLOW_EMPTY_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password) 設置為 true), Docker 容器啟動的時候, 將為服務器的 root 用戶生成一個隨機密碼. 密碼打印到容器的 stdout, 可以通過查看容器的日志找到密碼(參閱 [啟動 MySQL 服務器實例](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-getting-started.html#docker-starting-mysql-server)).
- [`MYSQL_ONETIME_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_onetime_password): 為 true 時(這是它的默認狀態, 除非 [`MYSQL_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-root-password) 被設置或者 [`MYSQL_ALLOW_EMPTY_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password) 設置為 true), root 用戶的密碼設置為過期, 必須先更改密碼, MySQL 才能正常使用.
- [`MYSQL_DATABASE`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_database): 這個變量允許你在鏡像啟動時指定創建的數據庫的名稱. 如果使用 [`MYSQL_USER`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_user_password) 和 [`MYSQL_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_user_password)指定了用戶名和密碼, 創建用戶并收錢超級用戶對其的訪問權限 (對應 `GRANT ALL`). 通過 [CREATE DATABASE IF NOT EXIST](https://dev.mysql.com/doc/refman/8.0/en/create-database.html) 語句創建指定的數據庫, 如果數據庫已存在則該變量無效.
[`MYSQL_USER`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_user_password), [`MYSQL_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_user_password): 這些變量用戶創建用戶并設置密碼, 授予通過 [`MYSQL_DATABASE`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_database) 變量指定數據庫的超級用戶權限. 在創建用戶時同時需要 [`MYSQL_USER`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_user_password) 和 [`MYSQL_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_user_password)—如果未設置兩個變量中的任何一個, 則忽略零一個變量. 如果同時設置了這兩個變量, 但是沒有設置 [`MYSQL_DATABASE`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_database), 那么創建的用戶沒有任何權限.
> **注意**
>
> 不需要使用這個機制來創建 root 超級用戶, which is created by default with the password set by either one of the mechanisms discussed in the descriptions for [`MYSQL_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-root-password) and [`MYSQL_RANDOM_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_random_root_password), 除非 [`MYSQL_ALLOW_EMPTY_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password) 為 true.
- [`MYSQL_ROOT_HOST`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-root-host): 默認情況下, MySQL 創建 `'root'@'localhost'` 賬號. This account can only be connected to from inside the container as described in [Connecting to MySQL Server from within the Container](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-getting-started.html#docker-connecting-within-container). 允許其它主機進行 root 連接, 設置此環境變量. 例如, `172.17.0.1`, 這是默認的 Docker 網關 IP, 允許運行容器的主機連接. 該選項只接受一個入口, 但是允許通配符(例如, `MYSQL_ROOT_HOST=172.*.*.*` 或者 `MYSQL_ROOT_HOST=%`).
- [`MYSQL_LOG_CONSOLE`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-log-console): 當變量為 true (這是 MySQL 8.0 服務器容器默認的狀態), MySQL 服務器的錯誤日志被重定向到 `stderr`, 所以錯誤日志就進入到 Docker 容器的日志并且可以使用 `docker logs mysqld-container` 命令查看.
> **注意**
>
> 如果服務器配置文件是從主機中掛載的, 則該變量不起作用 (參閱 [持久化數據和配置更改](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-persisting-data-configuration) 中的 bind-mounting 配置文件).
- [`MYSQL_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-root-password): 該變量為 MySQL root 賬號之指定一個密碼.
> **警告**
>
> 在命令上設置 root 用戶密碼是不安全的. 作為顯式指定密碼的替代方法, you can set the variable with a container file path for a password file, and then mount a file from your host that contains the password at the container file path. 這仍然不是很安全, 密碼文件的位置仍然處于公開狀態. 最好使用 [`MYSQL_RANDOM_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_random_root_password) 和 [`MYSQL_ONETIME_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_onetime_password) 的默認設置都為 true.
- [`MYSQL_ALLOW_EMPTY_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password). 設置它為 true 允許以 root 用戶空密碼啟動容器.
> **警告**
>
> 設置此變量為 true 是不安全的, 因為它將使你的 MySQL 實例完全不受保護, 允許任何人獲得完整的 root 用戶訪問權限. 最好使用 [`MYSQL_RANDOM_ROOT_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_random_root_password) 和 [`MYSQL_ONETIME_PASSWORD`](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql_onetime_password) 的默認設置都為 true.
- 簡介
- 前言和法律條款
- 安裝和更新 MySQL
- 在 Linux 上安裝 MySQL
- 在 Linux 上使用 APT 庫安裝 MySQL
- 在 Linux 上使用 Docker 部署 MySQL
- 使用 Docker 部署 MySQL 服務器的基本步驟
- 使用 Docker 部署 MySQL 服務器的更多主題
- 教程
- 連接到服務器和從服務器斷開
- 輸入查詢
- 創建和使用數據庫
- 創建和選擇數據庫
- 創建表
- 將數據加載到表中
- 從表中檢索數據
- 選擇所有數據
- 選擇特定行
- 選擇指定列
- 行排序
- 日期計算
- 處理 NULL 值
- 模式匹配
- 計算行數
- 使用多個表
- 獲取數據庫和表的信息
- 在批處理模式使用 mysql
- 常見查詢示例
- 列的最大值
- 包含某一行最大值的記錄
- 每組中列的最大值
- 擁有某個字段的組間最大值的行
- 使用用戶自定義變量
- 使用外鍵
- 兩個鍵上搜索
- 計算每日訪問量
- 使用 AUTO_INCREMENT
- 在 Apache 中使用 MySQL
- MySQL 程序
- MySQL 客戶端程序
- mysql — MySQL 命令行客戶端
- 優化
- 優化概述
- 優化 SQL 語句
- 優化和索引
- 優化數據庫結構
- 優化 InnoDB 表
- 優化 MyISAM 表
- 優化 MEMORY 表
- 理解查詢執行計劃
- 控制查詢優化器
- 緩沖和緩存
- 優化鎖操作
- 優化 MySQL 服務器
- 測量性能 (Benchmarking)
- 檢查線程信息