zoukankan      html  css  js  c++  java
  • mysql创建用户以及授权

    Mysql新建用户操作

    方法一:

    mysql> insert into mysql.user(Host,User,Password)  values("localhost","zhangs",password("123456"));

    mysql> flush privileges;

    解释这样就创建了一个用户名为zhangs,密码为123456的数据库用户;此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。

    方法二:

    mysql> create user 'username'@'localhost' identified by 'password';

    username:指定要新建的用户名

    localhost:指定该用户在哪个主机上可以登录,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符%。

    Password:该用户的登陆密码,密码可以为空。

    方法三:

    mysql> grant all on *.* to 'qq'@'%' identified by '123456';

    删除用户:

    mysql>Delete FROM user Where User='test' and Host='localhost';

    mysql>flush privileges;

    mysql>drop database testDB; //删除用户的数据库

    删除账户及权限:

    mysql>drop user 用户名@'%';

    mysql>drop user 用户名@ localhost; 

    授权

    授权test用户拥有所有数据库的某些权限:   

    mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

    授予所有权限:

    mysql>grant all on *.* to test@"%" identified by "1234";

    授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限):

    mysql>grant all privileges on testDB.* to test@localhost identified by '1234';

    mysql>flush privileges;

    注意:

    用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:

    mysql>GRANT ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

    查看权限:

    mysql> show grants; //查看当前用户的权限

    mysql> show grants for 用户名;

    mysql> show grants for zhangs@'localhost';

    取消权限:

    mysql> revoke all on databasename.tablename from 'username'@'host';

  • 相关阅读:
    (Good Bye 2019) Codeforces 1270B Interesting Subarray
    (Good Bye 2019) Codeforces 1270A Card Game
    Codeforces 1283D Christmas Trees(BFS)
    Codeforces 1283C Friends and Gifts
    Codeforces 1283B Candies Division
    1095 Cars on Campus (30)
    1080 Graduate Admission (30)
    1099 Build A Binary Search Tree (30)
    1018 Public Bike Management (30)
    1087 All Roads Lead to Rome (30)
  • 原文地址:https://www.cnblogs.com/duanlinxiao/p/10543764.html
Copyright © 2011-2022 走看看