我认为这是不可能的,但问一下也没有什么坏处。
我有这个sql文件:
LOAD DATA INFILE 'myfile.csv'
INTO TABLE TCONTACTN4DS
FIELDS TERMINATED BY ";"
LINES TERMINATED BY "\r\n"
如果INFILE选项中没有路径,则前往data/name_of_the_DB文件夹获取文件。
我可以在 infile 中放置任何路径,但假设我不知道将使用的路径,并且我不希望更改这些脚本。
我可以声明(不知 Prop 体在哪里)一个可以更改以描述路径的全局变量吗?如果可能的话我会如何使用它?
最佳答案
load data infile 上的 mysql 文档关于这一点非常明确,所以不,你不能这样做:
The server uses the following rules to locate the file:
If the file name is an absolute path name, the server uses it as given.
If the file name is a relative path name with one or more leading components, the server searches for the file relative to the server's data directory.
If a file name with no leading components is given, the server looks for the file in the database directory of the default database.
由于加载数据也不能在存储例程中使用,因此您甚至无法解决此限制。
关于mysql - MySQL 中的全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35579880/