![]() ![]() When importing data into the discounts table, you can transform it into MySQL date format by using STR_TO_DATE() function:įirst, truncate the discounts table: TRUNCATE TABLE discounts Suppose the expired date column in the discount2.csv file is in the mm/dd/yyyy format: id,title,expired date,amountġ,Spring Break, 01/ 01/ 2014, 20 2,Back to School, 09/ 01/ 2014, 25 3,Summer Holiday, 08/ 25/ 2014, 10 Code language: PHP ( php ) In simple cases, you can transform it by using the SET clause in the LOAD DATA INFILE statement. Sometimes the format of the data does not match the target columns in the table. Notice that if you don’t place the file in the directory specified by the secure_file_priv variable, you’ll get the following error: ERROR 1290 (HY000): The MySQL server is running with the -secure-file-priv option so it cannot execute this statement Code language: JavaScript ( javascript ) Transforming data while importing | 3 | Summer Holiday | 2014 -08 -25 | 10.00 |ģ rows in set (0.00 sec) Code language: JavaScript ( javascript ) This is useful when the first row contains headers and should not be imported as data.įinally, retrieve the data from the discounts table to verify the import: SELECT * FROM discounts
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |