首页 > 数据库 > mysql教程 > mysql命令模式导出导入csv文件代码

mysql命令模式导出导入csv文件代码

WBOY
发布: 2016-06-07 17:51:05
原创
1193 人浏览过

我们可以利用mysql 命令模式来导入或导出csv文件哦,有需要的朋友可以简单的参考一下。

> * from tt_address;
+-----+-----+--------+--------+------+--------+------------+-------------+------
-----+----------+-------+------------------------+-------+--------+-----+-------
--+----------+------+---------+------+-----+--------+---------+-------+-----+---
------+-------------+--------------+---------------------------+----------------
-------+
| uid | pid | tstamp | hidden | name | gender | first_name | middle_name | last_
name | birthday | title | email                  | phone | mobile | www | addres
s | building | room | company | city | zip | region | country | image | fax | de
leted | description | addressgroup | module_sys_dmail_category | module_sys_dmai
l_html |
+-----+-----+--------+--------+------+--------+------------+-------------+------
-----+----------+-------+------------------------+-------+--------+-----+-------
--+----------+------+---------+------+-----+--------+---------+-------+-----+---
------+-------------+--------------+---------------------------+----------------
-------+
|   2 |  42 |      0 |      1 |      | m      | aa         |             | aa
     |        0 |       | tian.li@atop-online.de |       |        |     |
  | d        |      |         |      |     |        |         |       |     |
    0 |             |            0 |                         0 |
     0 |
+-----+-----+--------+--------+------+--------+------------+-------------+------
-----+----------+-------+------------------------+-------+--------+-----+-------
--+----------+------+---------+------+-----+--------+---------+-------+-----+---
------+-------------+--------------+---------------------------+----------------
-------+
1 row in set (0.00 sec)
这个表里的只有一条数据,现在我导出的csv文件里只需要有uid,name,gender,email,module_sys_dmail_html.命令行如下:select uid,name,gender,email,module_sys_dmail_html into outfile 'd:\test7.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by 'n' from tt_address
cvs文件导入MySql命令:
mysql> load data local infile 'e:\input1.csv' into table test1 fields terminated by ','lines terminated by 'n'(first_name,last_name,email);

FIELDS TERMINATED BY ---- 字段终止字符
FIELDS OPTIONALLY ENCLOSED BY ---- 封套符
LINES TERMINATED BY ---- 行终止符

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板