select * from foobar into outfile '/tmp/schrodinger_cat.c-6ren">
gpt4 book ai didi

MySQL select into outfile "file already exists"和 "file does not exist"对偶(?)案例

转载 作者:行者123 更新时间:2023-11-29 02:14:00 29 4
gpt4 key购买 nike

我在 CentOS 机器的 MariaDB 上成功运行了这个命令:

MariaDB> select * from foobar into outfile '/tmp/schrodinger_cat.csv'
fields terminated by ',' enclosed by '"' lines terminated by '\n';

Query OK, 900 rows affected (0.06 sec)

猫还活着?没有。

您希望找到“/tmp/schrodinger_cat.csv”。我也是。我 ls 它:

# ls /tmp/schrodinger_cat.csv

ls: cannot access /tmp/schrodinger_cat.csv: No such file or directory

猫死了?没有。

什么?所以我回到 MariaDB 命令行客户端并再次运行相同的 SQL:

MariaDB> select * from foobar into outfile '/tmp/schrodinger_cat.csv'
fields terminated by ',' enclosed by '"' lines terminated by '\n';

ERROR 1086 (HY000): File '/tmp/schrodinger_cat.csv' already exists

Cat 是否专为 MariaDB 而生?没有。

我想也许 MariaDB 正在访问另一个文件系统?所以我尝试了这个:

MariaDB> \! ls /tmp/schrodinger_cat.csv;

ls: cannot access /tmp/schrodinger_cat.csv: No such file or directory

所以,不。

知道发生了什么事吗?如何获取文件“/tmp/schrodinger_cat.csv”?

最佳答案

事实证明它是 MariaDB 独有的。

# ls /tmp/systemd-private-*-mariadb.service-*/tmp

/tmp/systemd-private-xxxxxxxxxxxxxxxxxxxxx-mariadb.service-xxx/tmp:
schrodinger_cat.csv

原因是CentOS systemd服务文件设置PrivateTmptrue:

[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql

ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

# Place temp files in a secure directory, not /tmp
PrivateTmp=true

[Install]
WantedBy=multi-user.target

您可以从 this RedHat blog post 中找到更多信息.如果 PrivateTmp=true,进程将有一个私有(private)的 /tmp 文件夹。

原来这只猫在一座私有(private)城堡里还好好地活着:-)

关于MySQL select into outfile "file already exists"和 "file does not exist"对偶(?)案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43796115/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com