• MySQL创建用户和权限管理


    转自:https://www.cnblogs.com/zhaohaiyu/p/11459613.html

    一、如何创建用户和密码

    1.进入到mysql数据库下

    mysql> use mysql
    Database changed

    2.对新用户增删改

    1.创建用户

    # 指定ip:192.118.1.1的chao用户登录
    create user 'chao'@'192.118.1.1' identified by '123';
    # 指定ip:192.118.1.开头的chao用户登录
    create user 'chao'@'192.118.1.%' identified by '123';
    # 指定任何ip的chao用户登录
    create user 'chao'@'%' identified by '123';

    2.删除用户

    drop user '用户名'@'IP地址';

    3.修改用户

    rename user '用户名'@'IP地址' to '新用户名'@'IP地址';

    4.修改密码

    set password for '用户名'@'IP地址'=Password('新密码');

    二、给当前的用户授权

    #查看权限
    show grants for '用户'@'IP地址'
    
    #授权 chao用户仅对db1.t1文件有查询、插入和更新的操作
    grant select ,insert,update on db1.t1 to "chao"@'%';
    
    #授权 chao用户仅对db1文件有查询的操作
    grant select on db1.* to "chao"@'%';
    
    # 表示有所有的权限,除了grant这个命令,这个命令是root才有的。chao用户对db1下的t1文件有任意操作
    grant all privileges  on db1.t1 to "chao"@'%';
    #chao用户对db1数据库中的文件执行任何操作
    grant all privileges  on db1.* to "chao"@'%';
    #chao用户对所有数据库中文件有任何操作
    grant all privileges  on *.*  to "chao"@'%';

    三、移除当前用户的权限

    #取消权限
     
    # 取消chao用户对db1的t1文件的任意操作
    revoke all on db1.t1 from 'chao'@"%";  
    
    # 取消来自远程服务器的chao用户对数据库db1的所有表的所有权限
    
    revoke all on db1.* from 'chao'@"%";  
    
    取消来自远程服务器的chao用户所有数据库的所有的表的权限
    revoke all privileges on *.* from 'chao'@'%';
     
    
  • 相关阅读:
    CCF CSP 201403-2 窗口
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
  • 原文地址:https://www.cnblogs.com/gdwkong/p/13220568.html
Copyright © 2020-2023  润新知