Quantcast
Channel: 钻戒 and 仁豆米
Viewing all articles
Browse latest Browse all 290

Mysql中的数据导出成CSV

$
0
0

大促期间,需要把收集的监控数据倒出来,弄成excel,然后用图表画出来。方法如下:

select time_stamp,y_values from monit02 where metric = 'db.conn.all' and  time_stamp>'2016-05-26' and time_stamp < '2016-05-27'  
into outfile '/tmp/db-all.csv'  
fields terminated by ',' optionally enclosed by '"' escaped by '"'  
lines terminated by '\r\n';  

导出的数据如下:

"2016-05-26 00:00:03",918.00
"2016-05-26 00:01:03",912.00
"2016-05-26 00:02:03",912.00
"2016-05-26 00:03:03",922.00
...

注意格式,基本是用,号隔开,如果字段长,用”号包含。

如果要导入:

load data infile '/tmp/db-all.csv'  
into table monit02  
fields terminated by ','  optionally enclosed by '"' escaped by '"'  
lines terminated by '\r\n';  

Viewing all articles
Browse latest Browse all 290

Trending Articles