mariadb 无法规范化--secure-file-priv的参数

svujldwt  于 2022-11-08  发布在  其他
关注(0)|答案(3)|浏览(342)

我需要执行一个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

p3rjfoxz

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)。


# Prevent accessing /home, /root and /run/user

ProtectHome=true

并设置ProtectHome=false
如果你有其他目录的问题(/usr/boot/etc),检查ProtectSystem选项。如果问题与/tmp-检查PrivateTmp
文件:https://www.freedesktop.org/software/systemd/man/systemd.exec.html

eulz3vhy

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不存在,这就是原因。

wpcxdonn

wpcxdonn3#

我不知道这是否是最好的解决方案,但它在Linux(Ubuntu 20.04.4 LTS,MariaDB:10.6.7-玛丽亚数据库)。
1.在顶级目录(即/)上创建文件夹

sudo mkdir mysql

1.更改是对0777的权限

sudo chmod 0777 mysql

1.将其所有权更改为mysql

sudo chown mysql:mysql mysql

1.更改.cnf文件中的权限

sudo gedit /etc/mysql/mariadb.conf.d/50-server.cnf

1.在[mysqld]段中添加行

secure-file-priv = /mysql

1.重新启动mysql服务

sudo systemctl restart mysql.service

1.将表导出为csv文件

SELECT * INTO OUTFILE '/mysql/fileName.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM tableName;

就是这样,您已经成功地将表导出为csv文件。

相关问题