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';

  • 相关阅读:
    ecshop后台新建一个模块,添加分页
    Mysql中设置远程访问的方法
    Thinkphp 3.2中文章详情页的上一篇 下一篇文章功能
    Thinkphp 3.2.2 利用phpexcel完成excel导出功能
    Thinkphp 3.2中字符串截取
    服务管理-文件服务器
    nginx-伤心的事
    shell-awk
    shell-sed
    shell-函数、数组、正则
  • 原文地址:https://www.cnblogs.com/duanlinxiao/p/10543764.html
Copyright © 2011-2022 走看看