Bulk import data to mysql without specifying file extension - mysql

I am trying to load data from files to MySQL, but the files don't have an extension. How can i load the files without specifying the file extension?

Use LOAD DATA INFILE, it doesn't require any file extension. You just name your file.
Both of the following would work fine:
LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;
LOAD DATA INFILE 'data' INTO TABLE db2.my_table;
The command-line equivalent of LOAD DATA INFILE, mysqlimport, says this in its doc:
For each text file named on the command line, mysqlimport strips any extension from the file name and uses the result to determine the name of the table into which to import the file's contents. For example, files named patient.txt, patient.text, and patient all would be imported into a table named patient.

I believe we can't pass a directory to LOAD DATA INFILE without specifying the complete file name . I did a merge of all the files to a single file and then ingested the data

Related

Ingest multiple excel files to MySQL using query

I am trying to load data from excel files into a table in MySql. There are 400 excel files in .xlsx format.
I have successfully ingested one file into the table but the problem is that involves manually converting excel file into a csv file, saving it on a location and then running a query to load using LOAD LOCAL INFILE. How to do it for rest of the files.
How to load all the 400 .xlsx files in a folder without converting them manually to .csv files and then running the ingestion query one by one on them.Is there a way in MySql to do that. For example, any FOR Loop that goes through all the files and ingest them in the table.
Try bulk converting your XLSXs into CSVs using in2csv as found in csvkit.
## single file
in2csv file.xlsx > file.csv
## multiple files
for file in *.xlsx; do in2csv $file > $file.csv; done
Then import data into MySQL using LOAD LOCAL INFILE...
From loading multiple CSVs, use for file in *.csv; do... or see How to Import Multiple csv files into a MySQL Database.

Trying to load text file in mysql but error is no such file or directory

I am trying to load (a.txt) file into mysql with the load command, but it says no such file or directory even if file is present at the specified path?
load data local infile 'F:\makarand\a.txt'
into TABLE file;
load data local infile 'F:\makarand\a.txt'
into TABLE file;
I have tried this also tried by removing local word but the issue remains same
It says:
Error No 2:No such file or directory
File is a protected name in MYSQL
https://dev.mysql.com/doc/refman/8.0/en/keywords.html
It expects a filename now, rather than your suggested table. Either rename the table (use a pre- or suffix) or try to quote it in your query. These kind of things sadly happen, thus I always use a prefix on my tables, to make sure i dont encounter this kind of things.
// edit //
See also this topic. This has nothing to do with Windows or Linux
Load data infile, difference between Windows and Linux

Possible to load one gzip file of muliple CSVs in Redshift

I am trying to load a compressed file which contain multiple CSV files into Redshift. I followed AWS documentation Loading Compressed Data Files from Amazon S3. However, I am not sure if I will be able to do following:
I have multiple CSV files for a table:
table1_part1.csv
table1_part2.csv
table1_part3.csv
I compressed these three files into one table1.csv.gz.
Can I load this gzip file into Redshift table using COPY command?
No you cannot; but using copy command you can give a folder name (containing all zip files) or wild card .. So just dont zip them into one file but independent files will work fine.
You could achieve by creating a Menifest file that should have link of all your CSV files and just specify the Menifest file in your copy command like-
copy customer
from 's3://mybucket/cust.manifest'
iam_role 'arn:aws:iam::0123456789012:role/MyRedshiftRole'
manifest;
See Menifest at end.
For more details refer Amazon Red-Shift Documentation. Section "Using a Manifest to Specify Data Files".

how can I load multiple csv files in a directory to neo4j with a single load

I have a folder with 620 file I need to load all to neo4j with one load command is this is possible
You can concatenate all the files in that folder into a single file (e.g., cat * >all_data.csv) and load that single file.
The import-tool supports reading from multiple CSV source files, even using a regex pattern to select them. See http://neo4j.com/docs/operations-manual/current/#import-tool

Import only a chunk from a file with LOAD DATA

Is there a way to import only a chunk from a file with LOAD DATA in MySQL, or must I partition the file manually?
you have to partition the file manually.
because LOAD DATA will Load the complete file in table.
you can use :
LOAD DATA INFILE
...
IGNORE x LINES
DOCS
You would not be able to import only a chunk from a file. You would have to partition the file manually. Because load data will load the complete file.