With mysql, 4 typical methods to import data into a database are to iport the data, loading text data and dumping a csv file from Excel, or importing data from a xml file. This tutorial discusses loading the data from a text file.
The file below is contents of a text(.txt) file. Note that line 1 just tells us what the two database table columns could be.
The text below would add the file(my_file.txt) shown above into a database table called canadian_cities.
Decyphering the command:
The file myfile.txt gets loaded into the table canadian_cities which is in the database called world_cities.
The fields are terminated by ‘\t’ which means there is a tab space between the two columns; in this case between country name CAN and a city like Toronto.
Lines terminated by ‘\r\n’ means that each new line is a new row in the table.
IGNORE 1 LINES means the first line with the junk text ‘Country City’ is not inserted into the database. In order to load the data, we had already set the table and columns up. You could omit this condition if you deleted the first line ‘Country City’.
© 2018 ALL Rights Reserved | Sitemap
Vancouver | North Vancouver | Burnaby | Richmond | Coquitlam | Port Coquitlam | Surrey | Langley | Maple Ridge | Mission | Abbotsford | Kamloops | Kelowna | Victoria | Squamish | Whistler | Pemberton