MySql insert txt file with insert statements
I am wondering what the best format is to insert data via a txt file.
I have entered few values separated by a tab index. And it works fine. But i would liek my file to look neat and tidy !! I would like them to be readable, as several value s will simple create a endless lomg line. So I want a txt file, that includes the insert into statement and readable data such as each field underneath each other . . with commas, nrackets e.g. (see below)
What am I doing wrong, as I am not able to read in those data fields. As said, I am able to read tab separated values without the insert statement within the file ( I put that in the command line) But I would like to put these also into the txt file !
Thanks for any hints in this matter
INSERT INTO COUPON(
id,
title,
product_description,
product_name,
current_price,
original_price,
business_name,
business_description,
fine_print,
start_date,
end_date,
start_time,
end_time,
min_coupons,
max_coupons,
mem_id,
deal_status)
VALUES(
'4',
'tile',
'product description',
'product name here',
'15.000',
'30.000',
'name'开发者_JAVA百科,
'example',
'fine print!',
'2011-03-24',
'2011-03-25',
'12:00:00',
'12:00:00',
'10',
'20',
'1936',
'N'),
( . . .), ( . . .), . . . .
using tools like phpmyadmin, Navicat you can export+import in CSV (comma separated value) format. if you wanna see the file readable "arranged in columns" open it with MS-excel.
also this can do csv export from CMD:
mysql -umysqlusername -pmysqlpass databsename -B -e "select * from \`tabalename\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > mysql_exported_table.csv
source: http://forums.mysql.com/read.php?79,11324,204768#msg-204768
info about the command: http://www.debianadmin.com/export-mysql-database-into-a-csv-file.html
精彩评论