mysql 新增、删除用户和权限分配


  本文标签:mysql,权限

1. 新增用户

复制代码 代码如下:

mysql>insert into mysql.user(Host,User,Password) values("localhost","lionbule",password("hello1234"));
mysql>flush privileges;

2. 修改用户密码

复制代码 代码如下:

mysql>update mysql.user set password=password(new password) where User="lionbule" and Host="localhost";
mysql>flush privileges;

3. 删除用户

复制代码 代码如下:

mysql>DELETE FROM user WHERE User="lionbule" and Host="localhost";
mysql>flush privileges;

4. 权限分配

    4.1. grant用法
           grant 权限 on 数据库.* to 用户名@登录主机 identified by 密码

复制代码 代码如下:

权限:
    常用总结, ALL/ALTER/CREATE/DROP/SELECT/UPDATE/DELETE
数据库:
     *.*                    表示所有库的所有表
     test.*                表示test库的所有表
     test.test_table  表示test库的test_table表    
用户名:
     mysql账户名
登陆主机:
     允许登陆mysql server的客户端ip
     %表示所有ip
     localhost 表示本机
     192.168.10.2 特定IP
密码:
      账户对应的登陆密码

4.2 例子

复制代码 代码如下:

mysql>grant all  on test.* to lionbule@% identified by hello1234;
mysql>flush privileges;

新增密码为‘hello234的用户lionbule对test库拥有所有操作权限,并不限制lionbule用户的登陆IP 。    

4.3 注意事项

grant 会覆盖用户的部分信息,跟insert 、update执行功能一样.

参考:
http://dev.mysql.com/doc/refman/5.6/en/grant.html