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 ...
随机推荐
- DateTime小综合
实现效果: 关键知识: 1>DateTime类的ToString()方法: 2>DateTime类的IsLeapYear(); 3>DateTime类的DaysInMomth(); ...
- 【luogu P3371 单源最短路径 】 模板 SPFA优化
无优化:500ms deque优化:400ms #include <queue> #include <cstdio> #include <cstring> #inc ...
- 深入 Struts2 的配置 - 处理多个请求-处理请求结果-模型驱动-异常机制
转:http://www.java3z.com/cwbwebhome/article/article2/2938.html?id=1631 本部分主要介绍struts.xml的常用配置. 1.1. ...
- SpringBoot非官方教程 | 第十五篇:Springboot整合RabbitMQ
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot15-rabbitmq/ 本文出自方志朋的博客 这 ...
- Shiro 登录认证源码详解
Shiro 登录认证源码详解 Apache Shiro 是一个强大且灵活的 Java 开源安全框架,拥有登录认证.授权管理.企业级会话管理和加密等功能,相比 Spring Security 来说要更加 ...
- iOS之报错“Cannot create __weak reference in file using manual reference counting”解决办法
解决的办法:在Build Settings--------->Aplle LLVM8.0 - Language - Objectibe-C------------->Weak Refere ...
- 使用缓存时出现java.io.NotSerializableException:xxx.xxx.xxx.Bean解决办法
解决方案: 开发过程中如果想缓存某个JavaBean,请确保它所引用的对象都implents Serializable,如果某个对象不需要被cache,可以加上transient关键字,否则Ehc ...
- JSONP 通用函数封装
function jsonp({url, params, callback}) { return new Promise((resolve, reject) => { let script = ...
- 【CodeForces 803 C】Maximal GCD(GCD+思维)
You are given positive integer number n. You should create such strictly increasingsequence of k pos ...
- 通过xshell在linux上安装redis3.0.0
通过xshell在linux上安装redis3.0.0 0)首先要安装环境:yum install gcc-c++ 1)通过xftp6将redis安装包上传到linux:解压缩:tar -xvfz r ...