• mysql常用命令添加外键主键约束存储过程索引


    数据库连接

    mysql -u root -p123456

    查看表

    show databases

    创建数据库设置编码

    create table books character set utf8;

    创建用户

    -- 特别需要注意,在 MySQL 中,账号由两部分组成:
    -- 1. user
    -- 2. host
    -- 即使 user 相同,只要 host 不同,也会被认为是不同账号。
    -- 这样可以非常方便对来自不同 ip 地址的访问进行精细的权限控制。
    -- 默认情况下,创建的用户 host 为 '%',这是一个匹配符,跟模糊查询里的意思一样,表示匹配所有
    create user [用户名] identified by '[密码]';
    create user vip identified by 'vippp'; -- 所有连接 create user vip@'127.0.0.1' identified by 'xxx'; -- 本地连接 create user vip@'192.168.%' identified by 'yyy'; -- 192.168 网段的连接

    修改密码

    set passwor from '用户名' @host=password('新密码');

    update mysql.user set password=password('新密码') where user='用户名' and host='%';

    删除用户

    drop user 用户名;

    delete from mysql.user where user='用户名' and host='%'

    给权限

    grant all on *.* to vip@'127.0.0.1';   --将所有数据库上的所有权利都授予通过本机连接的VIP用户;

    grant all privileges on books.* to vip@'%'; --将数据库books上的说有权利都授予所有连接的vip用户;

    grant select on books.users to vip@'%';  --将books数据库上的users表的访问权限开发给vip用户;

    grant all on *.* to vip@'%' with grant potions;  --witgrant potionss的意思是可以给vip给予权限给别的用户

    查看权限

    show grants for vip@'%';

    进行冲刷

    flush privileges

     查看当前用户

    select user() ,current_user();

    创建表

    create table 表名

    判断存在就删除然后创建

    creata table if exists 表名  

    drop table if exists 表名

    创建临时表

    create temporary table 表名

    mysql自增长

    auto_increment

    添加外键约束

    alter table 表名 add constraint fk_引用id foreign key(引用id) references 被引用表名 (被引用id)

    添加主键约束

    alter table 表名 add constraint pk_id primary key (id);

    删除约束

    alter table 表名 drop forign key fk_引用id

    添加表的字段

    alter table 表名 add 字段名 类型 ;

    修改表中的字段为空

    alter table 表名 modify 字段名  类型  null

    修改表中的字段不为空

    alter table 表名 modify 字段名  类型 not null

    添加表的字段自增主键

    alter table 表名 add column 字段名 类型 auto_increment not null, add primary key(cid);

    删除表的字段

    alter table 表名 drop column 字段;

    删除表的主键

    alter table 表名 drop primary key;

    创建存储过程  mysql存储100相加的和

    create procedure sum(a int)
    begin
    set @i=0;
    set @j=0;
    repeat
    set @i=@i+1;
    set @j=@i+@j;
     until a=@i end
    repeat;
     end $

     --能整除三 不能整除9

    delimiter $
    create procedure asdw(sss int)
    begin
    set @i=0;
    set @cj=1;
    repeat
    set @i=@i+1;
    if @i%3=0 && @i%9!=0 then 
    set @cj=@cj*@i;
    end if;
    until @i=sss end repeat;
    end

     创建索引

    CREATE INDEX  索引名字 ON 表名(字段名)



  • 相关阅读:
    (selenium+python)_UI自动化02_元素定位
    (selenium+python)_UI自动化01_Mac下selenium环境搭建
    2019_Chrome和ChromeDriver对应关系
    charles_02_模拟弱网测试
    charles_01_打断点修改接口请求&返回数据
    Jmeter和LoadRunner的区别
    Linux 系统结构,nglinx
    jmeter,badboy,jar包文件 常数吞吐量计时器?
    863公司 linux软测题
    linux centOS 7 GUI安装
  • 原文地址:https://www.cnblogs.com/weibanggang/p/9594963.html
Copyright © 2020-2023  润新知