MySQL配置(Windows)定义新用户权限,数据库对用户开放权限

(1).查看目前mysql的用户
  select user,host,password from mysql.user
(2).修改root密码
  set password for root@localhost=password('yourpassword');
  例如:set password for root@127.0.1.1=password('yourpassword');
(3).删除匿名用户,执行以下sql
查看是否有匿名用户:select user,host from mysql.user;
删除匿名用户:delete from mysql.user where user='';
再次查看:select user,host from mysql.user;
刷新,使以上操作生效:flush privilehes;
(4).插入mysql新用户
  GRANT USAGE ON *.* TO 'user01'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
用户:user01,密码:123456,这样就添加了一个新的用户,mysql用户表的中某些字段不能为空,没有默认值,其实是操作错误,mysql添加用户是不能这样直接insert user表的。
使以上操作生效:flush privileges;
对你需要分配权限的数据库进行操作:例如我这边的数据库是Student
创建数据库语句:
  CREATE DATABASE `lair` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
(5).本地用户赋予所有权限
  grant all privileges on Student.* to 'yourusername' @localhost identified by 'yourpassword';
  Student.* 指代Student数据库的所有表
(6).给账号开通外网所有权限
  grant all privileges on Student.* to 'yourusername' @'%' identified by 'yourpassword';
  @'%' 意思为不限制ip
  例如:
  grant select,insert,update on Student.* to yourusername@'127.11.11.1' identified by 'yourpassword';
  意思为:为Student下所有表开通查询,增加,修改的权限(删除权限未授权,并且IP地址为127.11.11.1,也可为数据库下单独表设置权限
  使以上操作生效:flush privileges;

查看MySQL用户权限:

show grants for 你的用户


Windows:执行ipconfig查看运行mysql服务器的ip地址

posted on 2018-05-17 01:11  EastChilde  阅读(401)  评论(0编辑  收藏  举报

导航