美文网首页
mysql用户与权限

mysql用户与权限

作者: 海边的蜗牛ng | 来源:发表于2018-06-17 14:56 被阅读0次

    mysql.version=5.7 (必须注意版本)

    创建用户

    • ( CREATE USER 'bob'@'%' IDENTIFIED BY '07fa533360d9'; ) 创建bob用户 密码:07fa533360d9
    • ( CREATE USER "test"@"localhost" IDENTIFIED BY '123456' )创建test用户 密码123456
    • ( CREATE USER "test"@"192.168.87.26" IDENTIFIED BY '123456' )创建test用户 密码123456

    参数说明:'%'表示所有情况都能访问;'localhost'表示本机才能访问;'192.168.87.26' 某个具体 ip 才能访问

    授权命令 (GRANT privileges ON databasename.tablename TO 'username'@'host' )

    GRANT SELECT,INSERT privileges on spring.* to 'alice'@'localhost' identified by '123456'

    参数说明:databasename表示数据库名字;tablename数据库表的名字;username用户名;host表示链接地址如本机localhost,远程任意%,具体ip192.168.87.26

    授权test用户拥有testDB数据库的所有权限

    create database testDB;
    grant all privileges on testDB.* to "test"@"localhost" identified by '123456'
    

    指定部分权限给用户

    grant select,update on testDB.* to "blake"@"localhost" identified by '123456';
    GRANT SELECT, INSERT ON spring.user TO 'alice'@'localhost'; 
    

    撤销权限

    REVOKE privilege ON databasename.tablename FROM 'username'@'host'; #撤销
    REVOKE grant option ON databasename.tablename FROM 'username'@'host'; #收回
    

    修改用户密码

    update mysql.user set authentication_string=password('123456') where User='blake' and Host='localhost';
    

    关于修改密码也可以这样
    1:select password('1234'); 得到string 如1234==>*A4B6157319038724E3560894F7F932C8886EBFCF

    update mysql.user set authentication_string="*A4B6157319038724E3560894F7F932C8886EBFCF" where User='bob' and Host='localhost';
    

    关于远程访问修改

    UPDATE user SET Host='%' WHERE User='alice' AND Host='localhost' LIMIT 1;
    
    UPDATE user SET Host='192.168.87.26' WHERE User='alice' AND Host='%' LIMIT 1;
    
    

    删除用户bob

    delete from user WHERE User='bob'
    

    刷新系统权限表

    flush privileges; 
    

    查看权限

    show grants for 'blake'@'localhost';
    

    相关文章

      网友评论

          本文标题:mysql用户与权限

          本文链接:https://www.haomeiwen.com/subject/lheweftx.html