我需要执行一个load_file()
语句。文档告诉我必须通过将secure_file_priv
设置为""
来禁用secure_file_priv
,或者应该将其设置为path
。如果不是这样,load_file()
将返回NULL
。
- 当我编辑
my.cnf
并将mysqld-group
中的此变量设置为""
时,我可以重新启动mariadb,而不会出现任何问题。-如果我将此变量设置为路径(secure_file_priv="/path/"
),则会得到以下输出:
sudo systemctl restart mariadb.service
Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.
> sudo systemctl status mariadb.service
mariadb.service - MariaDB 10.1 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2017-09-12 10:50:59 CEST; 13s ago
Process: 4815 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 5306 ExecStart=/usr/libexec/mysqld --basedir=/usr $MYSQLD_OPTS $_WSREP_NEW_CLUSTER (code=exited, status=1/FAILURE)
Process: 5271 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
Process: 5249 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 5306 (code=exited, status=1/FAILURE)
Status: "MariaDB server is down"
sep 12 10:50:57 BEL002.HOME systemd[1]: Starting MariaDB 10.1 database server...
sep 12 10:50:58 BEL002.HOME mysql-prepare-db-dir[5271]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
sep 12 10:50:59 BEL002.HOME mysqld[5306]: 2017-09-12 10:50:59 139800931358976 [Warning] Failed to normalize the argument for --secure-file-priv.
sep 12 10:50:59 BEL002.HOME mysqld[5306]: 2017-09-12 10:50:59 139800931358976 [ERROR] Aborting
sep 12 10:50:59 BEL002.HOME systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
sep 12 10:50:59 BEL002.HOME systemd[1]: Failed to start MariaDB 10.1 database server.
sep 12 10:50:59 BEL002.HOME systemd[1]: mariadb.service: Unit entered failed state.
sep 12 10:50:59 BEL002.HOME systemd[1]: mariadb.service: Failed with result 'exit-code'.
我已经执行了chmod 777 /path/
。
如果我将secure_file_priv
设置为""
,选择load_file("file name")
仍然返回NULL
。
如何禁用secure_file_priv
?
3条答案
按热度按时间p3rjfoxz1#
这可能是由于systemd保护造成的。对我来说,在Debian 10 buster上,我也遇到过类似的问题:
如果
secure-file-priv=/home
- daemon启动,但在SELECT ... INTO OUTFILE
时失败。如果secure-file-priv=/home/username
- daemon启动失败,并出现Failed to normalize the argument for --secure-file-priv
错误。但如果我使用secure-file-priv的其他路径,则一切正常,只有/home目录是“特殊的”。简单修复:编辑mariadb systemd服务文件(对于debian,这是
/lib/systemd/system/mariadb.service
)。并设置
ProtectHome=false
。如果你有其他目录的问题(
/usr
,/boot
,/etc
),检查ProtectSystem
选项。如果问题与/tmp
-检查PrivateTmp
。文件:https://www.freedesktop.org/software/systemd/man/systemd.exec.html
eulz3vhy2#
我使用OpenSuSe LEAP 42.3
我在
/etc/my.cnf.d/secure_file_priv.cnf
中从secure_file_priv = /var/lib/mysql-files
个至
secure_file_priv = /var/lib/mysql
文件夹
/var/lib/mysql-files
不存在,这就是原因。wpcxdonn3#
我不知道这是否是最好的解决方案,但它在Linux(Ubuntu 20.04.4 LTS,MariaDB:10.6.7-玛丽亚数据库)。
1.在顶级目录(即
/
)上创建文件夹1.更改是对
0777
的权限1.将其所有权更改为
mysql
1.更改
.cnf
文件中的权限1.在
[mysqld]
段中添加行1.重新启动mysql服务
1.将表导出为csv文件
就是这样,您已经成功地将表导出为csv文件。