can LOAD DATA INFILE use a giving path instead of the default mysql data path? - mysql

I am trying to use LOAD DATA INFILE to upload xls/CSVfile content into mysql database.
the file in which I want to upload is located on a different path that the databases. I don't want to put the xls/CSV file in my same path as my data so I put them into a different path. but it seems that MySQL ignore the path I am providing It always searching for a file located in the data bases directory.
here is my code
LOAD DATA INFILE 'D:\uploads\new_campaign_request.xls'
INTO TABLE new_db.new_campaign
FIELDS TERMINATED BY ',';
How can I get MySQL to search for the file

LOAD DATA INFILE 'D:\\uploads\\new_campaign_request.xls'
INTO TABLE new_db.new_campaign(column_name)
FIELDS TERMINATED BY ',';
User double back slash for load file path and define column name in which data should be loaded

Related

global variable in MySQL

I dont think it is possible but there is no harm to ask.
I have this sql file :
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.
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.
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:
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.

How to use ftp file path for SQL loader?

I could not use ftp file path in SQL loader. Help to solve this problem.
LOAD DATA INFILE 'ftp file path'
TRUNCATE INTO TABLE temp
FIELDS TERMINATED BY ',' TRAILING NULLCOLS "(col1,col2)";
The string following the INFILE parameter needs to be the name of a file containing the data. See the documentation here: http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_control_file.htm#i1008015
If you are trying to make it a dynamic path to a file, you need to specify it on the command line when you call sql-Loader. In that case see the DATA parameter here: http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_params.htm#i1004682

Using LOAD DATA LOCAL INFLE for reading XML files

I know using LOAD XML LOCAL INFILE for reading XML files.
but i do not need to separate xml elements. I like to import whole xml file as a text.
Is it possible reading whole XML file as a text file?
I used this command
LOAD DATA LOCAL INFILE 'file.xml' INTO TABLE mytable;
the result is:
The query has been successfully implemented, 150 rows have been
affected.
But when i use SELECT * FROM mytable; it shows 150 empty lines!
Use this:
LOAD DATA LOCAL INFILE 'file.xml' INTO TABLE mytable
FIELDS TERMINATED BY '\n' LINES STARTING BY '';
just replace FIELDS TERMINATED BY value & LINES STARTING BY value as per your file.

Import txt file into my database with specific format

I am new to MySQL and I searched internet. Before I used CSV file or SQL file to import my data into DB. But now I have a text file with this format:
number
989399999999
989388888888
989384444444
This continues about 300 records. How can I import this to my database?
LOAD DATA INFILE
The LOAD DATA INFILE statement reads rows from a text file into a
table at a very high speed. The file name must be given as a literal
string.
LOAD DATA LOCAL INFILE 'C:\\Users\\hi\\Desktop\\abc.txt' INTO TABLE customer LINES TERMINATED BY '\n' IGNORE 1 LINES
Query is self explanatory I hope :)

MYSQL LOAD DATA INFILE Syntax Error - where is it wrong?

where is the Synthax error here?
LOAD DATA INFILE 'mysqlout_back.txt'
INTO TABLE temp (user,category,site,tld,ip,updated,date)
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n' ;
If you only want to load the data in specific columns, the go to the end:
LOAD DATA INFILE 'mysqlout_back.txt'
INTO TABLE temp FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'
(user,category,site,tld,ip,updated,date) ;
EDIT, regarding the file location in your comments:
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.
See the MySQL ref