SQL/MySQL/Backup Load/Load Data Into Table

Материал из SQL эксперт
Перейти к: навигация, поиск

Load data in txt file into database

Drop table Bird;
CREATE TABLE Bird (
    name VARCHAR(20), 
    owner VARCHAR(20),
    species VARCHAR(20), 
    sex CHAR(1), 
    birth DATE, 
    death DATE
);
  
INSERT INTO  Bird VALUES ("BlueBird","Joe","Car","f","1999-03-30",NULL);
  
/* Suppose that your Bird records can be described as shown here. 
(Observe that MySQL expects dates in "YYYY-MM-DD" format; 
this may be different from what you are used to.
*/
name    owner   species  sex   birth       death
Blue   Joe   cat      f      1993-02-04    
Yellow  Yin     cat      m      1994-03-17    
Red     Richard dog      f      1989-05-13    
    
/*
Note that if you created the file on Windows with an editor that uses 
\r\n as a line terminator, you should use:
*/
LOAD DATA LOCAL INFILE "/path/Bird.txt" INTO TABLE Bird
LINES TERMINATED BY "\r\n";



load text data into table

LOAD DATA INFILE "/textFileName.txt"
INTO TABLE quackers
FIELDS TERMINATED BY ";"
LINES TERMINATED BY "\r\n"
IGNORE 1 LINES;
/*
      Colons, by using ":"
      Semicolons, by using ";"
      Spaces, by using " "
*/