• MySQL之账号管理、建库以及四大引擎+案例


    1、查找数据库引擎

    show engines;

    2、创建数据库

    #create database 数据库名

    create database text;
    #完整写法
    create database if not exists text default charset utf8 collate utf8_general_ci;

    3、查找数据库

    show databases;

    5、账号管理

    #5.1、创建用户并设置密码
    create user zking identified by '123456';

    #5.2、切换用户
    use mysql;

    #5.3、查看用户信息
    #192.168.1.%  ipv4  ipv6
    select * from user;
    select host,user,authentication_String from user;

    4、删除数据库(神用户,建议禁用;)

    drop user zking;

     6修改密码

    set password for zking=password('1234');

     7刷新配置

    flush privileges;

     8授权(grant)

    #语法:grant all [pricilenges] on databasename.tablename to 用户名@'%'
    #garnt all on *.* to zking@'%';
    grant select,delete on t277.t_book to zking@'%';

    9撤权(revoke)

    #语法:revoke all [privileges] on dataasename.tablename from 用户名@'%';
    #revoke all on *.* from zking@'%';
    revoke select on t277.t_book from zking@'%';

    10查询权限

    show grants for zking;

    下面就是一个案例

    1. #decimal(5,2)
    2. #总共五位,整数位三位,小鼠位两位小数
    3. create table if not exists t_money(
    4. id int not null primary key auto_increment,
    5. money decimal(5,2)
    6. );
    7. select * from t_money;
    8. create table t_student(
    9. sid int not null primary key auto_increment comment '学生编号',
    10. sname varchar(20) not null comment '学生姓名',
    11. idcard varchar(18) not null comment '身份证号',
    12. sex char(1) default '1' comment '学生性别,1=男,0=女',
    13. createdate timestamp default current_timestamp comment '创建日期',
    14. unique(sname,idcard)
    15. )comment '学生信息表';
    16. create table t_score(
    17. sid int not null comment '学生编号',
    18. cid int not null comment '课程编号',
    19. score float default 0 comment '成绩',
    20. foreign key(sid) references t_student(sid)
    21. )comment '学生成绩表';
    22. #先删外表,再删主表
    23. insert into t_score(sid,cid,score) values(1,2,90.5);
    24. select * from t_student;
    25. select * from t_score;

    以上就是今天的分享!👀👀👀👀👀👀

  • 相关阅读:
    MES系统是如何解决工厂上的难题的?
    三百内蓝牙耳机哪款好?内行盘点四款三百内最好的蓝牙耳机
    Idea安装插件刷Leetcode
    节能与环保杂志节能与环保杂志社节能与环保编辑部2022年第6期目录
    安装MYSQL遇到问题:write configuration file卡主
    【Java】基础简单好题好思路总结
    【无标题】
    华为机试题:HJ6 质数因子
    [鹏城杯 2022]简单的php - 无数字字母RCE+取反【*】
    通过IP地址可以做什么
  • 原文地址:https://blog.csdn.net/m0_62246061/article/details/125451834