mysql 个人小总结

文章长期更新

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';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值