Mysql5.7 创建用户权限问题
1.通过mysql数据库的user表查看用户相关信息
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> desc mysql; //表结构 mysql> select host,user from user; +-----------+------+-------------------------------------------+ | host | user | password | +-----------+------+-------------------------------------------+ | localhost | root | *87F2746835A04895BB77E12AA5054A767******* | | qxyw | root | | | 127.0.0.1 | root | | | localhost | | | | qxyw | | | +-----------+------+-------------------------------------------+ rows in set (0.00 sec)
2.创建数据库
mysql> create database [databasename] default character set utf8 collate utf8_general_ci; Query OK, 1 row affected (0.00 sec)
3.创建用户
mysql> create user 'dba'@'%' identified by '*******'; Query OK, 0 rows affected (0.00 sec)
user表中host列的值的意义
% 匹配所有主机
localhost localhost不会被解析成IP地址,直接通过UNIXsocket连接
127.0.0.1 会通过TCP/IP协议连接,并且只能在本机访问;
::1 ::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1
4.对dba用户给予针对指定数据库进行增删改查的权限
#部分权限 mysql> grant select,insert,update,delete,create on databasename.* to username; Query OK, 0 rows affected (0.00 sec) #全部权限 mysql> grant all privileges on bee.* to dev; #drop权限 mysql> grant drop on databasename.* to username; Query OK, 0 rows affected (0.00 sec)
注意:修改完权限以后 一定要刷新服务,或者重启服务,刷新服务用:
flush privileges;
5.可以通过show grants命令查看权限,若想要在原来的基础上增加权限则继续执行grant
mysql> show grants for username; +----------------------------------------------------------------------------------------------------+ | Grants for username@% | +----------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'username'@'%' IDENTIFIED BY PASSWORD '*****************************************' | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON `[databasename]`.* TO 'username'@'%' | +----------------------------------------------------------------------------------------------------+ rows in set (0.00 sec)
6.通过revoke命令可以移除用户的相关权限
mysql> revoke drop on databasename.* from username; Query OK, 0 rows affected (0.00 sec) mysql> show grants for username; +----------------------------------------------------------------------------------------------------+ | Grants for username@% | +----------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'username'@'%' IDENTIFIED BY PASSWORD '*****************************************' | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `[databasename]`.* TO 'username'@'%' | +----------------------------------------------------------------------------------------------------+ rows in set (0.00 sec)
7.用户创建有所有权限和查看所有表,使用revoke drop 和 grant drop 删除权限
mysql> revoke drop on *.* from username; Query OK, 0 rows affected (0.00 sec) mysql> grant drop on *.* to username; Query OK, 0 rows affected (0.00 sec)
码字很辛苦,转载请注明来自朱一兵的博客的《Mysql5.7 创建用户权限问题》
2018-12-19
学习文章
评论
| Theme by 暴博客 基于Z-BlogPHP搭建
文章归档
最近发表
标签