举例说明:
新建一个数据库biao
Biao下建一张新的表pet
mysql> create database biao;
Query OK, 1 row affected (0.00 sec)
mysql> create table pet( name VARCHAR(20), owner varchar(20),
-> species varchar(20), sex char(1), birth DATE, death DATE);
Query OK, 0 rows affected (0.03 sec)
mysql> desc pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
现在去新建一个txt的文档,里面可以输入对应字段的值,每个字段值之间用“TAB”键分开
huanghuang wenbiao dog f 1989-10-12
doudou wenyi cat m 1989-10-05 1992-1-05
huanghuang wubiao dog m 2011-02
还有一点需要注意的是,并不是我的txt表可以任意放置,建议放到data/mysql下对应的库下
我的就是放到了data/mysql/biao下面去了
之后,进入数据库中
mysql> use biao;
mysql> load data local infile "aa.txt" into table pet;
Query OK, 4 rows affected, 8 warnings (0.00 sec)
Records: 4 Deleted: 0 Skipped: 0 Warnings: 8
mysql> select * from pet;
+------------+---------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+------------+---------+---------+------+------------+------------+
| huanghuang | wenbiao | dog | f | 1989-10-12 | 0000-00-00 |
| doudou | wenyi | cat | m | 1989-10-05 | 1992-01-05 |
| huanghuang | wubiao | dog | m | 0000-00-00 | 0000-00-00 |
| | NULL | NULL | NULL | NULL | NULL |
+------------+---------+---------+------+------------+------------+
4 rows in set (0.00 sec)