zoukankan      html  css  js  c++  java
  • ubuntu下mysql的用户添加、授权、取消授权

    一、添加用户

    新增用户会有两种方式的,一种是使用create命令,另一种是直接回使用grant 命令

    create user 名字@登陆地址 identified by "密码";
    
    grant select,update(权限) on 数据库名.表名 to 用户@登录地址 identified by '密码';
     
    insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));

    二、授权和取消授权

    1grant privileges on 数据库名.表名 to '用户名'@'登录地址' identified by '密码';
     
    2grant select,insert on 数据库名.表名 to '用户名'@'登录地址' identified by '密码';
     
    3grant all on *.* to '用户名'@'登录地址' identified by '密码';
     
    4grant all on 数据库名.* to '用户名'@'登录地址' identified by '密码';
     
    --让用户 拥有授权 权限
    5grant privileges on  数据库名.* to '用户名'@'登录地址' with grant option;
     
    --取消授权
    6revoke all on *.* from '用户名'@'登录地址';

    三、查看用户信息

    当然有查看全部的用户信息和单个的用户信息

    1select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user;
     
    2select * from mysql.user where user='用户名';
     
    3、show grants for '用户名'@'登录地址(%表示远程登录)';
    --查看当前用户的权限
    4、show grants; 
     
    --查看用户表的结构
    5、show mysql.user

    四、修改用户和删除用户

    --修改用户密码
    1set password for 'username'@'host' = password('newpassword');
     
    --当前用户修改自己密码
    2set password = passw ("newpassword");
     
    --使用update 更新用户
    3update user set password=password('123') where user='root' and host='localhost'; 
       flush privileges; 
     
    --删除用户 
    4delete from mysql.user where user='root' and host='%';
       flush privileges;
    ————————————————
    版权声明:本文为CSDN博主「每天加点分」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/lcf_lxf_ldy/article/details/87721073

    如果操作没生效请执行

    flush privileges;




  • 相关阅读:
    mysql concat
    (三)微信小程序之发送服务通知(模板消息)
    小型web服务器thttpd的学习总结(下)
    小型web服务器thttpd的学习总结(上)
    平方根倒数快速算法
    微信公众平台服务框架
    静态库动态库回顾
    RocketMQ常用命令
    rocketmq配置文件参数(broker-xx.properties)
    RocketmMQ的组成及相关概念
  • 原文地址:https://www.cnblogs.com/zhidong123/p/11821514.html
Copyright © 2011-2022 走看看