文章长期更新
linux下的mysql
进入
mysql -u root -p 回车
输入密码
显示所有 的数据库
show databases;
假设我们现在有的数据库有 aaa,bbb,ccc;我们要使用aaa
use aaa;
显示当前数据库中所有的表
show tables;
假设我们要创建一个叫做article的表 里面包含的项有 title,author,content,createtime,updatetime,type,id;
create table article
(
title varchar(200) not null, (not null 表示每次写入表中数据的时候 title不能为空)
author varchar(200) not null,
content text not null,
createtime varchar(200) not null,
updatetime varchar(200) not null,
type varchar(200) not null,
id int not null default 0 (default 0 设置id的默认值为0)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;(设置编码格式为utf8格式 ,保证中文不会乱码,如果是一般建立数据库,ENGINE。。。。。uft8可以不用加)
假设我们觉得某一项不想要 比如id 项
alter table article drop id;
假设我们想添加一项叫做 id
alter table article add id int not null;
(添加id项并且设置为int 格式 不能为空)
假设我想添加的id项在author项之后
alter table article add id int not null after author;
如果我们要向表中添加数据
insert into article
values
('小明是逗比','小红','小明是我见过最逗比的逗比','2016年8月','2016年8月','胡说','1');
如果我们要一次性添加多组数据
insert intoarticle
values
(...),(...),(...),....,();
如果我们要更新表中的某组数据的某一项比如title
update article set title='小明不是逗比' where id='1';
如果更改多项 title author
update article set title='小明不是逗比',author='小刚' where id='1';
如果我们要显示表中的数据
select * from article;
如果显示表中的某几项数据
select title,author,type from article;
显示我们特定数据
比如表中id 为1的数据
select * from article where id='1';
显示某几项
select title,author from article where id='1';
如果我们要删除数据
删除所有数据
delete from article;
删除某几项数据
比如删除表中id=1的数据
delete from article where id='1';