我在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
我想也许MariaDB正在访问另一个文件系统?所以我尝试了这个:
MariaDB> \! ls /tmp/schrodinger_cat.csv;
ls: cannot access /tmp/schrodinger_cat.csv: No such file or directory
所以,没有。
知道发生了什么事吗?我如何获得'/tmp/schrodinger_cat.csv'文件?
答案 0 :(得分:1)
原来它是MariaDB独有的。
# ls /tmp/systemd-private-*-mariadb.service-*/tmp
/tmp/systemd-private-xxxxxxxxxxxxxxxxxxxxx-mariadb.service-xxx/tmp:
schrodinger_cat.csv
原因是CentOS systemd服务文件集PrivateTmp
为true
:
[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
,则该流程将包含一个私密的/tmp
文件夹。
在一座私人城堡里,这只猫活得很好: - )