MySql使用插入语句插入txt文件

发布于 2024-10-22 11:11:57 字数 790 浏览 1 评论 0原文

我想知道通过 txt 文件插入数据的最佳格式是什么。

我输入了几个由制表符索引分隔的值。而且效果很好。但我希望我的文件看起来干净整洁!我希望它们是可读的,因为几个值将简单地创建一个无尽的 lomg 行。 所以我想要一个txt文件,其中包括insert into语句和可读数据,例如彼此下面的每个字段。 。用逗号,nrackets 例如(见下文)

我做错了什么,因为我无法读取这些数据字段。如前所述,我可以在文件中不使用插入语句的情况下读取制表符分隔的值(我将其放在命令行中),但我想将它们也放入 txt 文件中!

感谢您对此事的任何提示

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',
'example',
'fine print!',
'2011-03-24',
'2011-03-25',
'12:00:00',
'12:00:00',
'10',
'20',
'1936',
'N'),
( . . .), (  . . .), . . . .

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',
'example',
'fine print!',
'2011-03-24',
'2011-03-25',
'12:00:00',
'12:00:00',
'10',
'20',
'1936',
'N'),
( . . .), (  . . .), . . . .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-10-29 11:11:57

使用 phpmyadmin、Navicat 等工具,您可以以 CSV(逗号分隔值)格式导出+导入。如果您想查看可读的“按列排列”的文件,请使用 MS-excel 打开它。

这也可以从 CMD 导出 csv:

mysql -umysqlusername -pmysqlpass databsename -B -e "select * from \`tabalename\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > mysql_exported_table.csv

来源: http:// forums.mysql.com/read.php?79,11324,204768#msg-204768
有关命令的信息:http://www.debianadmin。 com/export-mysql-database-into-a-csv-file.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文