MySQL用户权限控制一例
(root@localhost mysql3306.sock)[(none)]>create user aaron8219@'192.168.1.%' identified by 'zlm';
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[(none)]>select user,host from mysql.user;
+---------------+-------------+
| user | host |
+---------------+-------------+
| rpl_mgr | % |
| aaron8219 | 192.168..% |
| repl | 192.168..% |
| replica | 192.168..% |
| zlm | 192.168..% |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-------------+
rows in set (0.00 sec) (root@localhost mysql3306.sock)[(none)]>grant all privileges on *.* to aaron8219@'192.168.1.%'; //Grant the supreme privileges to the user.
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[(none)]>show grants for aaron8219@'192.168.1.%';
+----------------------------------------------------------+
| Grants for aaron8219@192.168..% |
+----------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'aaron8219'@'192.168.1.%' |
+----------------------------------------------------------+
row in set (0.00 sec)
[root@zlm2 :: ~]
#mysql -uaaron8219 -pzlm -h192.168.1.
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (aaron8219@192.168.1.101 )[(none)]>show databases; //The user "aaron8219" can see all the databases in the current MySQL instance.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| sysbench |
| zlm |
+--------------------+
rows in set (0.01 sec) (aaron8219@192.168.1.101 )[(none)]>create database aaron8219;
Query OK, row affected (0.00 sec) (aaron8219@192.168.1.101 )[(none)]>use aaron8219;
Database changed
(aaron8219@192.168.1.101 )[aaron8219]>create table t1(
-> id int,
-> name char()
-> ) engine=innodb;
Query OK, rows affected (0.02 sec)
(root@localhost mysql3306.sock)[(none)]>create user aaron8219@'192.168.1.101' identified by 'zlm';
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[(none)]>select user,host from mysql.user;
+---------------+---------------+
| user | host |
+---------------+---------------+
| rpl_mgr | % |
| aaron8219 | 192.168..% |
| repl | 192.168..% |
| replica | 192.168..% |
| zlm | 192.168..% |
| aaron8219 | 192.168.1.101 |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+---------------+
rows in set (0.00 sec) (root@localhost mysql3306.sock)[(none)]>grant all privileges on aaron8219.* to aaron8219@'192.168.1.101'; //Grant the privileges only on "aaron8219" database.
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[(none)]>show grants for aaron8219@'192.168.1.101';
+----------------------------------------------------------------------+
| Grants for aaron8219@192.168.1.101 |
+----------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'aaron8219'@'192.168.1.101' |
| GRANT ALL PRIVILEGES ON `aaron8219`.* TO 'aaron8219'@'192.168.1.101' |
+----------------------------------------------------------------------+
rows in set (0.00 sec)
[root@zlm2 :: ~]
#mysql -uaaron8219 -pzlm -h192.168.1.
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (aaron8219@192.168.1.101 )[(none)]>show databases; //Only the "aaron8219" database can be list.
+--------------------+
| Database |
+--------------------+
| information_schema |
| aaron8219 |
+--------------------+
rows in set (0.00 sec) (aaron8219@192.168.1.101 )[(none)]>show grants for aaron8219@'192.168.1.101';
+----------------------------------------------------------------------+
| Grants for aaron8219@192.168.1.101 |
+----------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'aaron8219'@'192.168.1.101' |
| GRANT ALL PRIVILEGES ON `aaron8219`.* TO 'aaron8219'@'192.168.1.101' |
+----------------------------------------------------------------------+
rows in set (0.00 sec) (aaron8219@192.168.1.101 )[(none)]>use aaron8219;
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
(aaron8219@192.168.1.101 )[aaron8219]>show tables;
+---------------------+
| Tables_in_aaron8219 |
+---------------------+
| t1 |
+---------------------+
row in set (0.00 sec) (aaron8219@192.168.1.101 )[aaron8219]>insert into t1 values(,'abc');
Query OK, row affected (0.00 sec) (aaron8219@192.168.1.101 )[aaron8219]>select * from t1;
+------+------+
| id | name |
+------+------+
| | abc |
+------+------+
row in set (0.00 sec) //Eventrually,the privileges of account aaron8219@'192.168.1.%' has been restricted merely on database "aaron8219".
//Further more,we can revoke all the privileges on it either.
(root@localhost mysql3306.sock)[(none)]>revoke all privileges on aaron8219.* from aaron8219@'192.168.1.101';
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[(none)]>show grants for aaron8219@'192.168.1.101';
+---------------------------------------------------+
| Grants for aaron8219@192.168.1.101 |
+---------------------------------------------------+
| GRANT USAGE ON *.* TO 'aaron8219'@'192.168.1.101' |
+---------------------------------------------------+
row in set (0.00 sec)
[root@zlm2 :: ~]
#mysql -uaaron8219 -pzlm -h192.168.1.
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (aaron8219@192.168.1.101 )[(none)]>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
row in set (0.00 sec) (aaron8219@192.168.1.101 )[(none)]>create database test;
ERROR (): Access denied for user 'aaron8219'@'192.168.1.101' to database 'test' //This time,the account of aaron8219 login with ip "192.168.1.101" can do nothing in the target instance.
MySQL用户权限控制一例的更多相关文章
- Mysql用户权限控制(5.7以上版本)
1.1. 最简单的MySql权限 最简单也是最高效的,如果解决新手们删库跑路的问题其实也是很简单的,对于正式库只给一个增删改查的权限,或者只给一个查询权限(是不是就解决了删库的可能性?) 使用Ro ...
- mysql用户权限
mysql> show grants for root@'localhost';+-------------------------------------------------------- ...
- linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制)
linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制) 发表于2012//07由feng linux 本身的ugo rwx的权限,对于精确的权限控制很是力不从心的,ac ...
- Vue-Access-Control:前端用户权限控制解决方案
原文地址:http://refined-x.com/2017/11/28/Vue2.0用户权限控制解决方案/ Vue-Access-Control是一套基于Vue/Vue-Router/axios 实 ...
- asp.net core根据用户权限控制页面元素的显示
asp.net core根据用户权限控制页面元素的显示 Intro 在 web 应用中我们经常需要根据用户的不同允许用户访问不同的资源,显示不同的内容,之前做了一个 AccessControlHelp ...
- mysql用户权限操作
mysql用户权限操作1.创建用户mysql -urootcreate database zabbix default charset utf8;grant all on zabbix.* to za ...
- Linux上Mysql数据库 用户权限控制
Linux安装mysql 点我直达 Mysql限制root用户ip地址登录 修改mysql库里边的user表: update mysql.user set host='localhost' where ...
- 烂泥:nginx、php-fpm、mysql用户权限解析
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://ilanni.blog.51cto.com/526870/1561097 本文首发 ...
- MYSQL用户权限管理学习笔记
MYSQL 用户管理 1.权限表 MYSQL是一个多用户的数据库,MYSQL的用户可以分为两大类: (1) 超级管理员用户(root),拥有全部权限 (2) 普通用户,由roo ...
随机推荐
- 负的CPU保护环
什么是CPU保护环? 在计算机科学中, 分级保护域(英语:hierarchical protection domains),经常被叫作保护环(Protection Rings),又称环型保护(Ring ...
- apache php 与nginx php 的区别
apache是通过mod_php来解析php nginx是通过php-fpm(fast-cgi)来解析php 1. PHP 解释器是否嵌入 Web 服务器进程内部执行 mod_php 通过嵌入 PHP ...
- 【洛谷P2831】[NOIP2016]愤怒的小鸟
愤怒的小鸟 题目链接 本来是刷状压DP的,然而不会.. 搜索是比较好想的,直接dfs就行了 我们可以知道两只猪确定一条抛物线 依次处理每一只猪,有以下几种方法: 1.先看已经建立的抛物线是否能打到这只 ...
- 【luogu P2234 [HNOI2002]营业额统计】 题解
题目链接:https://www.luogu.org/problemnew/show/P2234 本来是一道打算练习splay的题目 发现暴力可以过啊.. #include <iostream& ...
- mysql-delete 和 truncate的区别
delete from student where id = 3; -- delete partly delete from student; -- delete all truncate stu ...
- 用$(this)选择其下带有class的子元素
$(this).find('.son').removeClass("disn")
- LeetCode15.三数之和 JavaScript
给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复的三元组. ...
- python学习笔记--数据类型
Life is short, You need Python! 霸气的口号! 今天我也开始学python了,毕竟不懂后端的前端不是好前端.之前有过‘世界上最好的语言’和JavaScript的学习经验. ...
- #leetcode刷题之路9- 回文数
判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1:输入: 121输出: true 示例 2:输入: -121输出: false解释: 从左向右读, 为 ...
- Configuration 中无法自动注入依赖于component的bean
出现问题时我这样使用依赖注入 @Configuration public class WebServiceConfig { @Autowired private IMessageWebService ...