用户管理:
1.用户的作用:
登陆
管理用户对象
2.用户的定义:
用户:用户名@'白名单'
例子:root@'localhost'
3操作用户:
查:
select user,host from mysql.user;
增:
create user oldguo@'localhost';
create user oldguo@'localhost' identified by 'oldguo123';
create user oldguo@'139.43.43.%' identified by 'oldguo123';
改:
alter user oldguo@'localhost' identified by 'oldguo';
删:
drop user oldguo@'localhost';
注意:8.0以前可以用grant命令创建用户,并授权。8.0以后只能用create。
注意:配置mysql的用户的白名单的时候需要用公网ip,我的mac查询公网ip的命令是:
curl ipinfo.io/json
例如我的是 luobiao @'171.217.81.44'
所以远程登陆是 :
mysql -uluobiao -p -h 139.129.93.203 -P 3306
权限管理:
作用
用户对数据库对象,有哪些管理权限.
权限的表现方式
具体的命令
查看mysql有哪些权限: show privileges;
授权,回收权限操作
语法 :
8.0以前:
grant 权限 on 对象 to 用户 identified by '密码';
8.0+:
create user 用户 identifued by '密码';
grant 权限1,权限2,..... on 对象 by 用户;
grant 权限 on 对象 to 用户 identified by '密码' with grant option;
权限:
All 管理员
权限1,权限2,权限3,....:普通用户(业务用户,开发用户)
grant option :给别的用户授权
对象:库,表
. :------>chmod -R 755 / mysql对应全部库全部表
luobiao.* mysql某个库对应的所有表
luobiao.t1 mysql某个库对应的某个表
授权例子:
例子1:创建并授权管理员用户,能够通过某个网段登陆并管理数据.
grant all on . to luobiao@'171.217.81.44' with grant option;
查询用户的权限:
show grants for 用户全名称;
例子2:创建并授权普通用户,能够通过某个网段登陆并只能进行增删该查和创建用户
grant create,select,update,delete,insert on mysql.* to test@'localhost' identified by 'luobiao123';
刷新数据库: flush privileges;
mysql的授权表:
.
select * from mysql.user \G 查看全库级别的授权;
具体库.*
select * from mysql.db \G 查看库级别的授权;
具体库.具体表
select * from mysql.tables_priv \G 查看表别的授权;
具体库.具体表.具体列
select * from mysql.columns_priv \G 查看表别的授权;
具体库.具体存储过程
select * from mysql.procs_priv \G 查看表别的授权;
回收权限:
Linux :
chmod -R 644 /oldguo ----->chmod -R 755 /oldguo 用过重新授权,修改权限
mysql:
不能通过重新授权修改权限
revoke 权限1,权限2 on 具体库 from 具体用户;
revoke create on mysql.* from test@'localhost';
msyql 中删除用户,用户的权限没了,用户创建的表和库依然存在,oracle中会消失。
面试题:
超级管理员密码忘记了,怎么处理?
处理思路,关闭数据库连接层的验证功能。
1.关闭数据库 systemctl stop mysqld
解决方案1:service mysqld start --skip-grant-tables
解决方案2:mysqld_safe --skip-grant-tables &
--skip-grant-tables & 跳过授权表 (缺点远程也可以连)
--skip-grant-tables 跳过tcp/ip连接
解决方案3:mysqld_safe --skip-grant-tables --skip-networking &
解决方案4:service start mysqld --skip-grant-tables --skip-networking
3.手工加载授权表 flush privileges;
4.进行修改密码 alter user root@'localhost' identified by 'luobiao123';
网友评论