MySQL-导入数据

以下:citeulike是数据库名,user_article是table名

create database citeulike;

create table user_article(user varchar(32), article varchar(12), tag varchar(40));

load data local infile 'path\\data.txt' into table user_article fields terminated by ',';

------------------------------------

删除列表:

delete from user_article;删除表里的内容,表仍在,表头不变

drop table user_article;

drop database citeulike;

------------------------------------

更改表项类型

用到timestamp类型,如果直接用timestamp类型,它默认default current_timestamp on update current_timestamp: 默认值是当前时间,并且该行其它项发生修改时自动更新时间

default current_timestamp:默认值是当前时间,不会自动更新时间

default 0/null:默认值是0/null

default 0/null on update current_timestamp:默认值是0/null,自动更新

on update current_timestamp:没写默认值,通常默认0

想把post_time的类型从current_timestamp on update current_timestamp改成default 0:

alter table user_article change post_time post_time timestamp default 0;

(改成default null显示错误:invalid default value for 'post_time')

在表里添加字段:

alter table article_abstract add title mediumtext;

------------------------------------

导出数据时

select * from user_article into outfile 'path\output.txt' fields terminated by '\t' lines terminated by '\r\n'; 显示:mysql server is running with the --secure-file-priv option so it cannot execute this statement

 

posted @ 2016-04-03 21:52  白天黑夜每日c  阅读(245)  评论(0编辑  收藏  举报