简体   繁体   English

MySQL中的全局变量

[英]global variable in MySQL

I dont think it is possible but there is no harm to ask. 我认为这是不可能的,但提出要求没有任何危害。

I have this sql file : 我有这个sql文件:

LOAD DATA INFILE 'myfile.csv'
INTO TABLE TCONTACTN4DS
FIELDS TERMINATED BY ";"
LINES TERMINATED BY "\r\n"

if there is no path in the INFILE option, it goest to the data/name_of_the_DB folder to get the file. 如果INFILE选项中没有路径,它将进入data / name_of_the_DB文件夹以获取文件。

I could put any path in the infile but let's assume that I dont know the path that will be used and I dont want those scripts to be changed. 我可以在infile中放置任何路径,但假设我不知道将要使用的路径,并且我不想更改这些脚本。

Can I declare (dont know where exactly) a global variable that could be changed to describe the path ? 我可以声明(不知道确切在哪里)可以更改以描述路径的全局变量吗? How would I use it if it is possible ? 如果可能的话,我将如何使用它?

The mysql documentation on load data infile is very explicit about this, so no, you cannot do this: 关于加载数据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. 如果给出的文件名中没有前导组件,则服务器将在默认数据库的数据库目录中查找该文件。

Since load data cannot be used in stored routines either, you cannot even have a workaround for this limitation. 由于加载数据也不能在存储的例程中使用,因此您甚至没有解决此限制的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM