Mysql用户基础操作
Linux用户的作用
登录系统
管理系统文件
Linux用户管理
创建用户:useradd adduser
删除用户:userdel
修改用户:usermod
Mysql用户的作用
登录Mysql数据库
管理数据库对象
Mysql用户管理
创建用户:create user
删除用户:delete user drop user
修改用户:update
用户的定义
username@'主机域'
主机域:可以理解为是Mysql登录的白名单
主机域格式:
10.1.1.12
10.1.0.1%
10.1.0.%
10.1.%.%
%
localhost
192.168.1.1/255.255.255.0
设定初始密码
[root@servera ~]# mysqladmin -uroot password '123456'
* 忘记root密码
[root@servera ~]# /etc/init.d/mysqld stop
[root@servera ~]# mysqld_safe --skip-grant-tables --skip-networking
# 修改root密码
mysql> update mysql.user set password=PASSWORD('123456') where user='root' and
host='localhost';
mysql> flush privileges;
用户管理
创建用户
mysql> create user user01@'192.168.175.%' identified by '123456';
查看用户
mysql> select user,host,password from mysql.user;
删除用户
mysql> drop user user01@'192.168.175.%';
用户权限介绍
权限
INSERT,SELECT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS,
FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY
TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE
VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER,
CREATE TABLESPACE
每次设定只能有一个属主,没有属组或其他用户的概念
mysql> grant all privileges on *.* to user01@''192.168.175.%''
identified by ''123''; 权限 作用对象 归属 密码
作用对象分解
. [当前MySQL实例中所有库下的所有表]
wordpress.* [当前MySQL实例中wordpress库中所有表(单库级别)]
wordpress.user [当前MySQL实例中wordpress库中的user表(单表级别)]
实验思考问题
#创建wordpress数据库
create database wordpress;
#使用wordpress库
use wordpress;
#创建t1、t2表
create table t1 (id int);
create table t2 (id int);
#创建blog库
create database blog;
#使用blog库
use blog;
#创建t1表
create table t1 (id int);
mysql> grant select on *.* to wordpress@’10.0.0.5%’ identified by ‘123’;
mysql> grant insert,delete,update on wordpress.* to wordpress@’10.0.0.5%’
identified by ‘123’;
mysql> grant all on wordpress.t1 to wordpress@’10.0.0.5%’ identified by ‘123’;
一个客户端程序使用wordpress用户登陆到10.0.0.51的MySQL后,
对t1表的管理能力?
对t2表的管理能力?
对tb1表的管理能力?
解
同时满足1,2,3,最终权限是1+2+3
同时满足了1和2两个授权,最终权限是1+2
只满足1授权,所以只能select
结论
如果在不同级别都包含某个表的管理能力时,权限是相加关系。
但是我们不推荐在多级别定义重复权限。
最常用的权限设定方式是单库级别授权,即:wordpress.*
Comments | NOTHING