mirror of
https://gitee.com/tawords/tawords-docs
synced 2025-02-28 09:33:36 +08:00
66 lines
1.5 KiB
Markdown
66 lines
1.5 KiB
Markdown
|
https://www.cnblogs.com/madman-fly/p/10742724.html
|
|||
|
【图片见原文】
|
|||
|
|
|||
|
1.首先在命令行启动mysql
|
|||
|
|
|||
|
net start mysql
|
|||
|
|
|||
|
|
|||
|

|
|||
|
|
|||
|
2.登录MySQL(建议使用非root用户)
|
|||
|
|
|||
|
mysql --local-infile=1 -u one -p
|
|||
|
|
|||
|
|
|||
|

|
|||
|
|
|||
|
3.创建数据库
|
|||
|
如 CREATE DATABASE menagerie;
|
|||
|
|
|||
|
在使用在这个数据库
|
|||
|
use menagerie
|
|||
|
|
|||
|

|
|||
|
|
|||
|
创建表
|
|||
|
|
|||
|
如:CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
|
|||
|
species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
|
|||
|
|
|||
|
创建后可以检查一下
|
|||
|
|
|||
|
show tables
|
|||
|
|
|||
|

|
|||
|
|
|||
|
验证表是否按预期方式创建
|
|||
|
|
|||
|
DESCRIBE pet;
|
|||
|
|
|||
|

|
|||
|
|
|||
|
4.创建好txt文件(最好存放在根目录下方便查找)
|
|||
|
|
|||
|
在数据库中导入
|
|||
|
|
|||
|
LOAD DATA LOCAL INFILE 'C:\pet.txt' INTO TABLE pet;
|
|||
|
|
|||
|
若报错
|
|||
|
|
|||
|

|
|||
|
|
|||
|
可将其改为绝对路径
|
|||
|
|
|||
|
LOAD DATA LOCAL INFILE 'C:\\pet.txt' INTO TABLE pet;
|
|||
|
|
|||
|
即可导入成功
|
|||
|
|
|||
|

|
|||
|
|
|||
|
select * from pet;
|
|||
|
|
|||
|
)
|
|||
|
|
|||
|
至此完成所有工作。
|