程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql命令模式導出導入csv文件代碼

mysql命令模式導出導入csv文件代碼

編輯:MySQL綜合教程

我們可以利用mysql 命令模式來導入或導出csv文件哦,有需要的朋友可以簡單的參考一下。

mysql> select * 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 |       | [email protected] |       |        |     |
  | 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 ---- 行終止符

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved