![]() ![]() If the fields are terminted by colon, you’ll use the following option in the above command: FIELDS TERMINATED BY ':' LOAD DATA INFILE 'employee2.txt'Īgain, use this option only when the field values are separated by anything other than TAB. To upload the above records to the employee table, use the following command.ĭuring the upload, using the “FIELDS TERMINATED BY” option, you can specify the comma field delimiter as shown below. In the following example, in the input file employee2.txt, the field values are separated by commas. Upload Data Using “Fields terminated by” Option Note: If you want to backup and restore your whole MySQL database, use mysqldump command. The second line displays the the total rows uploaded, how many were skipped and how many records displayed warnings during the upload.Īfter the data is loaded, the following is what we’ll see in the employee table.This also displays the time taken to upload the data from the text file to the table in seconds. It also says that total of 5 rows were uploaded to the table. The first line “Query OK” says that the query got executed without any error.Records: 5 Deleted: 0 Skipped: 0 Warnings: 0 The following will be the output of the above command. For example, if you are executing the above command in thegeekstuff database, then place the file under: /var/lib/mysql/thegeekstuff/ Note: In the above example, the command assumes that the employee1.txt file located under the database directory. This command doesn’t use any extra options. The following MySQL command will load the records from the above employee1.txt file to the employee table as shown below. In this example, we’ll upload the above employee1.txt file to the employee table located under thegeekstuff mysql database. # cat employee1.txtīy default, the load data infile command uses TAB as the default field delimiter.įirst, go to the database where you want to upload the text file. In the following example, the employee1.txt file has the field values that are separate by tab. Basic Example to Load Data From Text File Write Shell Script to Load data from Text Fileġ.Use Variable during Upload with “Set” Option.Upload Only Specific Columns (and Ignore Others) from Upload File.Ignore Header Line from the Upload File.Ignore Line Prefix in Upload File Using “Starting By” Option. ![]() Upload Data Using “Lines terminated by” Option.Upload Data Using “Fields terminated by” Option. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |