Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LOAD DATA INFILE on remote machine

Tags:

How would I do the following command, with a local file, on a remote database (different machine) ?

$MYSQL_PATH/mysql -u root -h remote.net files -e "     LOAD DATA INFILE '$1'     INTO TABLE $TABLE_NAME     FIELDS TERMINATED BY ','       (size, @d2, @d3, @d4, @d5, path) 

The problem seems to be that the INFILE at /tmp/infile.txt is not being recognized remotely. What would be the correct way to accomplish the above?

like image 452
David542 Avatar asked Mar 22 '13 20:03

David542


People also ask

What is load data infile?

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. If the LOCAL keyword is specified, the file is read from the client host. If LOCAL is not specified, the file must be located on the server. ( LOCAL is available in MySQL 3.22.

How does load data local infile work?

In contrast, when you execute the LOAD DATA LOCAL INFILE statement, the client attempts to read the input file from its file system, and it sends the contents of the input file to the MariaDB Server. This allows you to load files from the client's local file system into the database.

How do I enable local data Infile?

To disable or enable it explicitly, use the --local-infile=0 or --local-infile[=1] option. For the mysqlimport client, local data loading is not used by default. To disable or enable it explicitly, use the --local=0 or --local[=1] option.

How do I connect to the local Infile system variable?

To cause the server to permit access, set the local_infile variable with SET GLOBAL local_infile = 1; or check it with SHOW GLOBAL VARIABLES LIKE 'local_infile'; . Alternatively, edit mysql's config to include local_infile=1 .


2 Answers

LOAD DATA INFILE loads a file on machine the MySQL server is running on.

Use LOAD DATA LOCAL INFILE to load a file located on your client machine.

like image 89
nos Avatar answered Oct 20 '22 00:10

nos


Don't forget to include --local-infile=1 when doing this:

$MYSQL_PATH/mysql -u root -h remote.net files --local-infile=1 -e "     LOAD DATA LOCAL INFILE... 
like image 34
David542 Avatar answered Oct 20 '22 00:10

David542