• MySQL基础语句


    查看语句

    • 查看所有数据库
      show databases;

    • 查看表结构
      desc table_name;

    • 查看库中所有表
      show tables;

    • 查看建表语句
      show create table <table_name> ;

    新建表语句

    • 新建表:
    id int unsigned not null auto_increment comment '用户id',
    uesr_name varchar(20) not null comment '用户名',
    email varchar(50) not null comment '用户邮箱',
    age tinyint unsigned not null comment '用户年龄',
    fee decimal(10,2) not null default 0.00 comment '用户余额',
    created_at timestamp not null comment '注册时间',
    primary key(id) );
    
    Filed Type Null Key Default Extra
    id int(10) NO PRI NUll auto_increment
    uesr_name varchar(20) NO NUll
    email varchar(50) NO NUll
    age tinyint NO NUll
    fee decimal(10,2) NO 0.00
    created_at timestamp NO NULL
    • 字译说明
      • unsigned:无符号
      • tinyint:最小int
      • decimal:准确,不四舍五入
      • timestamp:时间戳
      • comment:备注

    DDL:

    alter table 修改表操作
    alter table 表名 modify 列名 列类型          --修改改列类型
    alter table 表名 change 原列名 新列名 列类型  --修改列名
    alter table 表名 add 列名 列类型 ...alter **字段后  放置位置              --添加列字段  
    alter table 表名 drop 列名   --删除列字段
    alter table 表名 rename/rename to 新表名      --重名命表名
    

    DML数据管理语言:

    • select语句
      select * from 表名

    • insert语句
      insert into插入表操作
      insert into 表名 (列名,列名)values (‘’,‘’);
      insert into 表名 values(‘’,‘’)需全部字段都填上
      password(‘123456’)密码函数加密
      show variables like '%char%' 查看字符编码
      set names gbk 设置字符编码,解决中文乱码显示(当前链接改,退出后恢复)

    • update语句
      update 表名 set 列=‘’where 列=‘’
      update 表名 set 列=‘’,列=‘’where 列=‘’
      update 表名 set 列=‘’where 列!=‘’
      update 表名 set 列=‘’where 列 in(1,2,4)
      update 表名 set 列=‘’where 列 between 2 and 5 修改2到5之间的

    • delete语句
      delete from 表名 where 列=‘’
      delete from 表名;整表删除
      truncate 表名;整表删除,重新插入id重新开始排

    DCL数据控制语言:

    • 修改密码
      1、update user set password-PASSWORD(‘新密码’) where user=‘用户名’
      2、mysqladmin -uroot -p旧密码 password 新密码

    • 忘记密码
      运行mysql.exe mysqld --skip-grant-tables 跳过权限,后台开进程进入mysql
      use mysql
      select user,host,password from user
      update user set password=password('新密码') where user='用户名'
      flush privileges刷新权限
      mysql -uu

    • 创建用户
      create user 用户名 @‘IP地址’ identified by ‘密码’
      限定的IP上使用,所有IP要用%
      mysql -u用户名 -h地址 -p密码

    • 用户授权
      grant 权限1,权限2,... on 数据库名.* to 用户名 @IP地址或%
      所有数据库用. 所有权限用all/all privileges

    • 撤销权限
      revoke 权限1,权限2..on 数据库名.* from 用户名 @IP地址或%

  • 相关阅读:
    三分法
    牛客网 TaoTao要吃鸡 ( 0/1背包变形 )
    POJ 3275 Ranking the cows ( Floyd求解传递闭包 && Bitset优化 )
    Codeforces 912E Prime Gift ( 二分 && 折半枚举 && 双指针技巧)
    Codeforces 912D Fishs ( 贪心 && 概率期望 && 优先队列 )
    Codeforces 919D Substring ( 拓扑排序 && DAG上的DP )
    队列构造拓扑排序
    Codeforces 919E Congruence Equation ( 数论 && 费马小定理 )
    Codeforces 916B Jamie and Binary Sequence ( 模拟 && 思维 )
    POJ 1769 Minimizing maximizer ( 线段树 && DP )
  • 原文地址:https://www.cnblogs.com/longmiao/p/12619510.html
Copyright © 2020-2023  润新知