MySql导入txt数据

来源:互联网 发布:php防sql注入原理 编辑:程序博客网 时间:2024/04/28 09:26

最近忙里抽闲看了一点Mysql, 这个Mysql我已经很久没用了(至少也有5年了),发现好多东西都记不得了。

比如导入文件只记得个大概,随意在网上翻了一下还是有很多资料了。然后自己试了一下,居然Pass了。

基本语法就是 load data local infile 'file path in local machine' into table table_name;

结合我自己的小练习,说详细点吧。

我先建了一个练习用的库,又在库里建 了一个表。然后创建了一个外部文件txt格式的

其中建创txt文件的过程有点小挫折,我不记得数据之间的间隔是什么了,试了空格,试了逗号,一直是报错啊,最后发现原来是Tab分隔。。囧啊

create database mytest; //create a sample database such as mytest
use mytest;  //Using this database
show tables; // no table lists
create table mytable //create a sample table mytable
(
name varchar(20),
sex char(1),
id int primary key auto_increment
);
load data local infile 'c:/working/mydata.txt' into table mytable; //import data from a local txt file.


0 0
原创粉丝点击