Home > database >  How to do the folder name and the name of the file as a list of import to the Mysql database respect
How to do the folder name and the name of the file as a list of import to the Mysql database respect

Time:10-29

Consult BBS's friends, I like batch to do the folder name and file name respectively as a list of import to Mysql database,
I built a table date20170801A at present, the existing field code like this:
[code=SQL] CREATE TABLE ` date20170801A ` (
` TranID ` varchar (255) the DEFAULT NULL COMMENT 'order no.,
` Time ` varchar (255) the DEFAULT NULL COMMENT 'closing Time,
` Price ` varchar (255) the DEFAULT NULL COMMENT 'clinch a deal the Price,
` Volume ` varchar (255) the DEFAULT NULL COMMENT 'clinch a deal the number of shares,
` SaleOrderVolume ` varchar (255) the DEFAULT NULL COMMENT 'number of seller's deity,
` BuyOrderVolume ` varchar (255) the DEFAULT NULL COMMENT 'number of buyer's deity,
` Type ` varchar (255) the DEFAULT NULL COMMENT 'transaction Type,
` SaleOrderID ` varchar (255) the DEFAULT NULL COMMENT 'number seller deity,
` SaleOrderPrice ` varchar (255) the DEFAULT NULL COMMENT 'the seller to hang the unit price,
` BuyOrderID ` varchar (255) the DEFAULT NULL COMMENT 'number buyer deity,
` BuyOrderPrice ` varchar (255) the DEFAULT NULL COMMENT 'buyer to hang the unit price'
) ENGINE=MyISAM DEFAULT CHARSET=GBK;

Questions as follows:
How do I put it in more than 3000 date20170801A CSV import table, and the table automatically add two fields used to identify the folder name and file name


Hope ace to help me solve the great god, no matter how to even give a concrete train of thought, thank you!


File price inside the CSV file header has created tables in mysql with me date20170801A field is consistent with the

CodePudding user response:

To table date20170801A added two fields is not ok, if is a Java can be directly get the file path and filename, save data when put together, other language estimation is also similar

CodePudding user response:

I've tried, can not ah

CodePudding user response:

MYSQL is not very familiar with, if is MS SQL Server, can consider to use filestream, for file operations,

CodePudding user response:

 
# the initial increase in two fields
The alter table date20170801A add column folder_name varchar (20);
The alter table date20170801A add column file_name varchar (20);

# for each file to import, use the following method
The LOAD DATA INFILE 'import documents'
INTO the TABLE date20170801A
(corresponding to the file content field list)
SET folder_name='directory name, file_name=' file name ';

CodePudding user response:

As for the LOAD DATA of specific requirements (for example, to specify a newline, etc.), refer to the website LOAD DATA of grammar

CodePudding user response:

reference 4 floor ZJCXC - personal WeChat public namesake reply:
 
# the initial increase in two fields
The alter table date20170801A add column folder_name varchar (20);
The alter table date20170801A add column file_name varchar (20);

# for each file to import, use the following method
The LOAD DATA INFILE 'import documents'
INTO the TABLE date20170801A
(corresponding to the file content field list)
SET folder_name='directory name, file_name=' file name ';


I have more than 3000 folders below CSV file that is each file imports to perform file import code is again

CodePudding user response:

Powershell script
The directory dir files according to *. CSV | % {
$f $fn, $fd=$_. FullName, $_. Name, $_. Dicrecory
@ "
The LOAD DATA INFILE '$f'
INTO the TABLE date20170801A
(corresponding to the file content field list)
SET folder_name='$fd, file_name=' $fn;
"@} | mysql - h localhost - u xx - PXXX the db

CodePudding user response:

refer to 7th floor ZJCXC - personal WeChat public namesake reply:

Powershell scriptThe directory dir files according to *. CSV | % {
$f $fn, $fd=$_. FullName, $_. Name, $_. Dicrecory
@ "
The LOAD DATA INFILE '$f'
INTO the TABLE date20170801A
(corresponding to the file content field list)
SET folder_name='$fd, file_name=' $fn;
"@} | mysql - h localhost - u xx - PXXX the db

Thank you you said two ways I can go to test it again
  • Related