具体方法:
(推荐教程:mysql数据库学习教程)
首先创建数据库
mysql> create database menagrie;
然后创建表
mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
接着将以下数据写入一个pet.txt文本中:
Fluffy Harold cat f 1993-02-04 \N Claws Gwen cat m 1994-03-17 \N Buffy Harold dog f 1989-05-13 \N Fang Benny dog m 1990-08-27 \N Bowser Diane dog m 1979-08-31 1995-07-29 Chirpy Gwen bird f 1998-09-11 \N Whistler Gwen bird \N 1997-12-09 \N Slim Benny snake m 1996-04-29 \N
使用以下命令实现导入数据库:
mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;
问题:
出现错误显示:ERROR 1148 (42000): The used command is not allowed with this MySQL version
原因:local_infile变量处于OFF,需要手动将其置于ON
mysql> SET GLOBAL local_infile=1;
完成后再导入数据即可。