Submitted by bawdo2001 on Tue, 2006-04-18 11:54.
Using command line tools to export data from a MySQL database into a CSV file is quite easy. Here's how:
mysql -uexampleuser -pletmein exampledb -B -e "select * from
\`person\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > filename.csv
Here is some sample output of the above:
"id","username","group","password"
"1","tux","admin","5f4dcc3b5aa765d61d8327deb882cf99"
"2","tlugian","admin","5f4dcc3b5aa765d61d8327deb882cf99"
"3","saiyuki","admin","5f4dcc3b5aa765d61d8327deb882cf99"
"4","fred","staff","5f4dcc3b5aa765d61d8327deb882cf99"
"5","barney","staff","5f4dcc3b5aa765d61d8327deb882cf99"
"6","wilma","admin","5f4dcc3b5aa765d61d8327deb882cf99"
And now for the explanation:
Starting with the MySQL command.
I wont explain the -u and -p options they are straight forward (if in
doubt man mysql). The -B option will delimit the data using tabs and
each row will appear on a new line. The -e option denotes the command
to run once you have logged into the database. In this case we are
using a simple SELECT statement.
Onto sed. The command used here contains three seperate sed scripts:
s/\t/","/g;s/^/"/ <--- this will search and replace all occurences of 'tabs' and replace them with a ",".
;s/$/"/; <--- This will place a " at the start of the line.
s/\n//g <---- This will place a " at the end of the line.
After running the result set through sed we redirect the output to a file with a .csv extension.
Regards, Bawdo2001
分享到:
相关推荐
mongodb文件导出csv的脚本, 使用OrderedDict制定有顺序的字段名, 极大方便了数据导出存储中啰嗦的字段重命名问题,字段缺失报错问题和字段排序问题. 根据项目实际情况进行配置和微调后即可使用.
关于如何将Grid 转换成CSV格式文件
export gridview to excel
ExportGrid4ToExcel的问题
给您二进制mysqlexport和ruby类Mysqlexport::Csv将mysql表导出到csv文件中。 安装 将此行添加到您的应用程序的Gemfile中: gem 'mysqlexport' 然后执行: $ bundle install 或自己安装为: $ gem install mysql...
* PHP code to export MySQL data to CSV * * Sends the result of a MySQL query as a CSV file for download * Easy to convert to UTF-8. */ /* * establish database connection */ $conn = mysql_...
export-csv Artwork by . Install [sudo]npm install --save export-csv Usages 默认使用gbk编码 var export_csv = require('.') var data = [ {a:1,b:2}, {a:2,b:2}, {a:3,b:2} ] export_csv(data, 'test1.csv')...
export mysql data to csv
用法示例import csvDownload from 'json-to-csv-export'... < button onClick = {() = > csvDownload(mockData)} > Download Data </ button >争论# 争论类型要求默认描述1个数据object required null
解决JsonException: Max allowed object depth reached while trying to export from type UnityEngine.Vector3
EMS Data Export:trade_mark: for MySQL是一款交叉平台的数据库工具,它用于快速将您的MySQL:registered:数据库导出为20种可用格式的文件,包括MS Access (只支持Windows:registered: 版本), MS Excel, MS Word (RTF...
Gain skills in MySQL’s fundamental features, including supported data types, database management syntax, triggers, views, stored routine syntax, and import/export capabilities Work with hundreds of...
Photoshop导出图层-Export-Layers-to-Files-Fast-master,Photoshop导出图层-Export-Layers-to-Files-Fast-master,Photoshop导出图层-Export-Layers-to-Files-Fast-master,
安装 npm install js-export-csv例子 import exportCSV from "js-export-csv"const data = [ ... Array ( 100 ) ] . map ( ( item ) => { return { name : "name" + item , code : "code" + item , year : "year" + ...
#Export-SQLite ExportSQLite是一个从MySQLWorkbench软件导出SQLite文件的插件。 我修改了最初由Thomas Henlich编写的脚本-http: 生成SQLite文件可以直接用于您的iOS或Android项目。 ##版本已使用MySQLWorkbench...
the way to create and export class from dll c++
基于C#实现的Datast与CSV导入与导出Import Export的程序类库代码。
轻量级的CSV导出类库,代码量小,使用简单,可以导出为File,TextWriter,HttpResponse。 有测试代码可供参考。 欢迎转载。
Follox提供了一个单击解决方案,导出中等追随者到CSV。 由于“中等追随者页面列表”以批量方式提取追随者列表,因此当用户拥有大量追随者并希望自动执行该过程时,该工具变得非常方便。 “如果没有Follox - 想象一下...
前端项目-highcharts-export-csv,用于将图表数据导出到csv、xls或html表的HighCharts插件