如何将 outfile 文件路径传递给 MySQL?我已经尝试过以下方法。这没用。
我的 SQL 文件
SET @query = CONCAT('SELECT *
FROM
`registered_user`
INTO OUTFILE ',@output_location,' FIELDS TERMINATED BY \',\'
LINES TERMINATED BY \'\n\'');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
我的命令行命令
mysql -u root -p test -e "set @output_location= '/var/tmp/out.csv'; source test2.sql;"
我收到以下错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/var/tmp/out.csv FIELDS TERMINATED BY ','
LINES TERMINATED BY '
'' at line 12
如果我只给它,它会起作用out.csv
。但我不知道文件存储在哪里。我错过了上述命令中的任何转义序列吗?
此问题已报告给 MySQL。但是有解决办法吗?