MySQL加载命令:数据文件是否有可用的通配符?
我每天都会将以下文件转储到我们的在线目录之一中:
dat-part2-489359-43535-toward.txt
数字每天都会随机变化。
我有以下代码来尝试加载文件:
mysql_query("LOAD DATA LOCAL INFILE 'dat-part2-%-toward.txt'
REPLACE INTO TABLE my_table
FIELDS TERMINATED BY ',' ENCLOSED BY ''
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES") or die(mysql_error());
当然没有运气。最好的方法是什么?
I have the following file dumped daily into one of our online directories:
dat-part2-489359-43535-toward.txt
The numbers change each day randomly.
I have the following code to try and LOAD the file:
mysql_query("LOAD DATA LOCAL INFILE 'dat-part2-%-toward.txt'
REPLACE INTO TABLE my_table
FIELDS TERMINATED BY ',' ENCLOSED BY ''
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES") or die(mysql_error());
And of course no luck. What's the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设这是一项计划作业,为什么不检查目录中是否有与您的文件名模板匹配的最新文件。将所述文件的名称存储在变量中,然后将该变量子到您的查询中。查看
glob()
assuming this is a scheduled job, why not check the directory for the most recent file that matches your filename template. Store the name of said file in a variable and then sub the variable into your query. Check out
glob()
我会通过 shell 脚本或 Windows cmd 文件来完成此操作。这假设您使用 mysqldump 或某些创建有效 sql 脚本的程序创建了该文件。
您可以在 windows 命令中运行 dir /B 来获取文件目录。所以做一个 dir /B > input.txt 然后使用 Windows 脚本读取输入文件,并针对每一行,使用 mysql 客户端通过管道传输该文件。
我已经很长时间没有编写任何 Windows 脚本了,但这应该能让您了解一种方法。
I would do it via a shell script or windows cmd file. This assumes you created the file with mysqldump or some program that creates a valid sql script.
You can run dir /B in windows commend to get a directory of files. So do a dir /B > input.txt then use Windows scripting to read the input file and for each line, pipe the file in using the mysql client.
It's been a long time since I wrote any windows scripts, but that should give you an idea of an approach.