MySQL text file import and batch mode application instructions

  • 2020-05-10 23:04:41
  • OfStack

1 load the records from the text file into the mysql database table
(1) text file format: 1 record per line, the field value is separated by tab locator, and the order of the field is 1 in the table definition; The uncertain field value is represented by \N.
(2) LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;
Note: if you are using the windows editor, you should use:
LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet
LINES TERMINATED BY '\r\n';

Run mysql in batch mode
(1) put the mysql statement you want to run into a text file batch-file. txt;
(2) execution: mysql-h host-u user-p < batch-file.txt;
(3) redirect the output to the file out.txt:
mysql -h host -u user -p < batch-file.txt > out.txt;
Run the script from the mysql prompt:
mysql > source batch - file. txt; Or mysql > \. batch-file.txt;

Related articles: