MySQL导入导出CSV格式

来自linux中国网wiki
Evan讨论 | 贡献2021年10月29日 (五) 08:04的版本
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索

table

针对 单个table  menu
MariaDB [mycmdb]> SELECT * INTO OUTFILE "/tmp/out.csv" FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'   FROM menu;
Query OK, 31 rows affected (0.014 sec)

-- 这里写你的sql 语句
select * from myUser 
into outfile '/tmp/test.csv' 
fields terminated by ',' optionally enclosed by '"' escaped by '"' 
lines terminated by '\r\n'; 


#一个例子
use  system;
select id,old_id,old_supplier_id,product_type,name,sales_platform,corporate_entity,insurancid from product where add_time < 16350 and supplier_id = 0 and old_id > 0 and deleted_at is null
into outfile '/tmp/test.csv' 
fields terminated by ',' optionally enclosed by '"' escaped by '"' 
lines terminated by '\r\n'; 






R

Bash中使用MySQL导入导出CSV格式数据[转]