mouhsineelachbi

insert_into_mysql_table_from_a_file

Oct 31st, 2020 (edited)
778
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. LOAD DATA INFILE "file.txt path"
  2. INTO TABLE tableName
  3. FIELDS TERMINATED BY ','
  4. LINES TERMINATED BY '\r\n';
  5.  
  6.  
  7.  
  8. Example of file content :
  9. 7839, KING, PRESENT, 0, 17-Nov-81, 22332, 0, 10
  10.  
  11. for schema :
  12. CREATE TABLE employer (
  13.     empno INT NOT NULL,
  14.     ename VARCHAR(45) NULL,
  15.     job VARCHAR(50) NULL,
  16.     mgr INT NULL,
  17.     hiredate VARCHAR(40) NULL,
  18.     sal INT NULL,
  19.     comm INT NULL,
  20.     deptno INT NULL,
  21.     PRIMARY KEY (empno)
  22. ); 
RAW Paste Data