MySQL创建用户及权限控制

来源:互联网 发布:mac下载的搜狗输入法 编辑:程序博客网 时间:2024/06/05 01:58

1.以root用户登录
2. 创建用户:

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

  这样就创建了一个名为:test 密码为:1234 的用户。
 注意:此处的”localhost”,是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将”localhost”改为”%”,表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。
3.为用户授权
  授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”; 

如果想指定部分权限给一用户,可以这样来写:
 

 mysql>grant select,update on testDB.* to test@localhost identified by '1234';  mysql>flush privileges; //刷新系统权限表 mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

设置root用户远程无法登陆
创建普通用户,无drop权限操作数据库

0 0