前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mysql数据库操作

mysql数据库操作

作者头像
超级大猪
发布2019-11-22 09:39:35
8250
发布2019-11-22 09:39:35
举报

就是这

http://7392072.blog.51cto.com/7382072/1325176

查询

# 附带条件
select * from qiushi_gif where source=20 and act_status<>7 order by id desc limit 10;

# 多重条件
select * from qiushi_gif where source=25 and created_at>'2017-04-16 17:50:42' and (act_status <> 7 or status='damage');

# 查询数量
select count(id) from qiushi_gif where source=20 and act_status<>7;

修改

update qiushi_gif set status='publish' where id=XX;

删除

delete from qiushi_gif where id = xx;

# 删库跑路
cat databases.txt | xargs -I XXX mysql -uroot -h10.0.8.45 -p'password' --default-character-set=utf8 -e "drop database XXX;"

创建表

普通表

create table USER(
    id int not null primary key auto_increment,
    name char(20) not null default '',
    age int(4) not null default 0,
    is_admin int not null default 0,
    created_time datetime not null default now()
    );

# 在远古时代也许是这样
create table news(
    id bigint(20) not null primary key auto_increment,
    title varchar(120) not null default '',
    content text not null default '',
    author varchar(100) not null default '',
    clicks int not null default 0,
    status int(8) not null default 0,
    category varchar(100) not null default '',
    created_time timestamp not null default CURRENT_TIMESTAMP
    )ENGINE=InnoDB DEFAULT CHARSET=utf8;

关联表

create table ARTICLE(
    id int not null primary key auto_increment,
    article_name char(20) not null default '',
    uid int not null default 0,
    article_pages int not null default 0,
    created_time datetime not null default now()
    );

alter table article add constraint `user_article` foreign key (uid) references user(id) on delete cascade on update cascade;

级联

left join

select news.id, news.title, news.created_time, pics.id as pid ,pics.url from news left join pics on (news.id = pics.nid) where news.created_time < %s and pics.status=3 limit %s;

修改表

alter table MyClass add passtest int(4) default '0';
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-04-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 就是这
  • 查询
  • 修改
  • 删除
  • 创建表
    • 普通表
      • 关联表
      • 级联
        • left join
        • 修改表
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档