• Mysql创建用户及授权


    通过root账号登陆数据库

    mysql -uroot -p
    
    • 1

    然后输入root账号密码

    创建要使用的库

    注:我是需要迁移mysql数据的时候操作的,所以我先创建了库,在创建用户,

    create database 库名;
    create database bj_bases_db;例如
    
    • 1
    • 2

    标题创建新用户,并授权该用户可以操作的数据库和表

    grant all privileges on 数据库名.表名 to '用户名'@'主机名' identified by '密码' with grant option;
    flush privileges; #刷新
    
    • 1
    • 2

    注释说明

    数据库名:如果为*,表示所有数据库 表名:
    如果为*,表示所有表
    *.*表示root权限,即满权限
    主机名:localhost表示仅允许本地连接,
    %表示本地和远程均可连接
    flush privileges;表示刷新权限,使授权生效

    所以允许远程连接的时候可以使用:

    grant all privileges on *.* to 'root'@'%' identified by 'root账号密码' with grant option;
    
    • 1

    比如我们新建test用户,授予该用户的权限是仅能操作test_database数据库,密码‘123’

    grant all privileges on test_database.* to 'test'@'%' identified by '123' with grant option;
    
    • 1

    标题修改用户密码

    update user set authentication_string = password(‘新密码’) where user = '用户名' and host = '主机名';
    
    • 1

    password()为mysql自身的一个加密函数
    以修改test用户密码为’456’为例

    update user set authentication_string = password('456') where user = 'test' and host = '%'
    • 1

    标题如何撤销用户权限

    revoke all on 数据库名.表名 from '用户名'@'主机名';
    
    • 1

    如何删除用户

    drop user '用户名'@’主机名‘;
    
    • 1
  • 相关阅读:
    2022年11月5日(星期六)骑行回回营村
    Miller_Rabbin算法判断大素数
    @ControllerAdvice 注解使用及原理探究
    redis的简单使用
    junit单元测试
    java中的Random
    SQL通配符
    利用labelme制作自己的coco数据集(labelme转coco数据集)
    Flutter-自定义短信验证码
    【漏洞复现】某厂商明御安全网关sslvpn命令执行漏洞
  • 原文地址:https://blog.csdn.net/weixin_45894220/article/details/126271873