To import data from a file to a database, use the load data local infile statement.
The default situation is as follows:
Tab is the field separator, and line feed is the record separator.
In this case, no additional conditions are required. simply use the most concise statement:
Load data local infile 'f:/pet.txt 'into Table PET;
Some situations are as follows:
Comma ',' is the field separator, and the line break is the record separator.
In this case, only the default delimiter of the record is used, and the field separation conditions must be added:
Load data local infile 'f:/pet1.txt 'into Table pet fields terminated ',';
There is also a situation like this:
Comma ',' is the field separator, '*,' is the record separator.
In this case, whether the field or record separator is not the default one, it should be described separately:
Load data local infile 'f:/pet2.txt 'into Table pet fields terminated by', 'Lines terminated '*,';
Query, use select * from PET; to test the data import result:
In each case:
OK. Import successful!