Where is the file located in Load Data Infile?

If I use the MySQL Load Data Infile query in PHP, where is the location of the file relatively? Is it the same folder as the PHP file?

+4
source share
3 answers

With LOAD DATA INFILE the file name refers to the server.

With LOAD DATA LOCAL INFILE file refers to the client.

If the server and the client are on the same computer, you can use LOAD DATA INFILE because it can handle key violations and other errors much better.

+4
source

From http://dev.mysql.com/doc/refman/5.1/en/load-data.html see the section that begins

If LOCAL is not specified, the file must be located on the server and read directly by the server. The server uses the following rules to find the file:

about a page and a half down.

Basically, you should specify the full path for the file. Relative paths refer to the MySQL server directory.

If you want to download the file from the web server where php is running on the database server where mysql is running (if they are different machines - often the same machine), obviously Mysql 5.1 has a mechanism for this and LOCALLY for that. I have never used this.

+1
source

No, this path is a server side path. Therefore, the file must be located on the same computer as the MySQL server.

I'm not sure about the working directory, but it should be where the database files are located (/ var / ...). You can use the absolute path to be sure.

But, as you can see, because in order to use the server machine, this is not a long-term solution.

0
source

Source: https://habr.com/ru/post/1300618/


All Articles