使用mysqlimport匯入資料到mysql

stonebox1122發表於2017-05-24

1、準備匯入資料
[root@D2-LZY245 ~]# cat /tmp/emp.txt
100,Steven,King,24000.00
101,Neena,Kochhar,17000.00
102,Lex,De Haan,17000.00
103,Alexander,Hunold,9000.00
104,Bruce,Ernst,6000.00
105,David,Austin,4800.00
106,Valli,Pataballa,4800.00
107,Diana,Lorentz,4200.00
108,Nancy,Greenberg,12008.00
109,Daniel,Faviet,9000.00
110,John,Chen,8200.00

 

2、建立InnoDB引擎表
mysql> create database test1;
Query OK, 1 row affected (0.00 sec)

mysql> use test1;
Database changed

mysql> create table emp(
    -> employee_id int(10),
    -> first_name varchar(50),
    -> last_name varchar(50),
    -> salary decimal(10,2)) engine=innodb charset=utf8;
Query OK, 0 rows affected (0.00 sec)

 

3、匯入資料
[root@D2-LZY245 ~]# mysqlimport -uroot -p'123456' test1 --default-character-set=utf8 --fields-terminated-by=',' /tmp/emp.txt
mysqlimport: [Warning] Using a password on the command line interface can be insecure.
test1.emp: Records: 11  Deleted: 0  Skipped: 0  Warnings: 0

 

4、檢視結果
mysql> select * from emp;
+-------------+------------+-----------+----------+
| employee_id | first_name | last_name | salary   |
+-------------+------------+-----------+----------+
|         100 | Steven     | King      | 24000.00 |
|         101 | Neena      | Kochhar   | 17000.00 |
|         102 | Lex        | De Haan   | 17000.00 |
|         103 | Alexander  | Hunold    |  9000.00 |
|         104 | Bruce      | Ernst     |  6000.00 |
|         105 | David      | Austin    |  4800.00 |
|         106 | Valli      | Pataballa |  4800.00 |
|         107 | Diana      | Lorentz   |  4200.00 |
|         108 | Nancy      | Greenberg | 12008.00 |
|         109 | Daniel     | Faviet    |  9000.00 |
|         110 | John       | Chen      |  8200.00 |
+-------------+------------+-----------+----------+
11 rows in set (0.00 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2139827/,如需轉載,請註明出處,否則將追究法律責任。

相關文章