Docker MySQL 8 如何设置--secure-file-priv
Docker MySQL 8 how to set --secure-file-priv
我想解决这个问题:
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
与 docker 上的 official MySQL 8 图片。
命令:
SHOW VARIABLES LIKE "secure_file_priv";
给出:
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
1 row in set (0.01 sec)
是否可以使用官方 MySQL 8 Docker 图像覆盖 --secure-file-priv 的默认值 NULL?
此图像中的默认值设置为 NULL
config/my.cnf
非常好,我想在使用 docker 运行 或创建时只设置一个环境变量或参数,而不是使用我自己的配置文件。
但如果这不可能,那么如何使用自定义配置文件?
自定义文件是否有可能只覆盖这个参数,而让其他参数保持在官方图像配置中?
根据this documentation,您可以通过传递 --secure-file-priv=dir_name
通过命令行配置 secure-file-priv
secure-file-priv 可能的值是:空字符串、dirname 或 NULL,如 privous url.
中所述
Configuration without a cnf file: Many configuration options can be passed as flags to mysqld. This will give you the flexibility to customize the container without needing a cnf file. For example, if you want to change the default encoding and collation for all tables to use UTF-8 (utf8mb4) just run the following:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
所以在我们的例子中是这样的:
dir_name should be a directory inside your container otherwise you will get the following error: mysqld: Error on realpath() on 'dir_name' (Error 2 - No such file or directory)
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --secure-file-priv=dir_name
现在我们的更改已在 MySQL
中提交
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+----------+
| Variable_name | Value |
+------------------+----------+
| secure_file_priv | dir_name |
+------------------+----------+
或者,您可以使用自定义配置文件,如下所述:
Using a custom MySQL configuration file: The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may !includedir additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d. Please inspect the relevant files and directories within the mysql image itself for more details.
If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):
$ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
这将启动一个新容器 some-mysql
,其中 MySQL 实例使用 /etc/mysql/my.cnf
和 /etc/mysql/conf.d/config-file.cnf
的组合启动设置,后者的设置优先。
我想解决这个问题:
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
与 docker 上的 official MySQL 8 图片。
命令:
SHOW VARIABLES LIKE "secure_file_priv";
给出:
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
1 row in set (0.01 sec)
是否可以使用官方 MySQL 8 Docker 图像覆盖 --secure-file-priv 的默认值 NULL?
此图像中的默认值设置为 NULL config/my.cnf
非常好,我想在使用 docker 运行 或创建时只设置一个环境变量或参数,而不是使用我自己的配置文件。
但如果这不可能,那么如何使用自定义配置文件? 自定义文件是否有可能只覆盖这个参数,而让其他参数保持在官方图像配置中?
根据this documentation,您可以通过传递 --secure-file-priv=dir_name
secure-file-priv
secure-file-priv 可能的值是:空字符串、dirname 或 NULL,如 privous url.
中所述Configuration without a cnf file: Many configuration options can be passed as flags to mysqld. This will give you the flexibility to customize the container without needing a cnf file. For example, if you want to change the default encoding and collation for all tables to use UTF-8 (utf8mb4) just run the following:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
所以在我们的例子中是这样的:
dir_name should be a directory inside your container otherwise you will get the following error:
mysqld: Error on realpath() on 'dir_name' (Error 2 - No such file or directory)
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --secure-file-priv=dir_name
现在我们的更改已在 MySQL
中提交mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+----------+
| Variable_name | Value |
+------------------+----------+
| secure_file_priv | dir_name |
+------------------+----------+
或者,您可以使用自定义配置文件,如下所述:
Using a custom MySQL configuration file: The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may !includedir additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d. Please inspect the relevant files and directories within the mysql image itself for more details.
If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):
$ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
这将启动一个新容器 some-mysql
,其中 MySQL 实例使用 /etc/mysql/my.cnf
和 /etc/mysql/conf.d/config-file.cnf
的组合启动设置,后者的设置优先。