mysql-命令

grant 授权

作用: 添加用户并设置权限
命令格式:

grant 权限列表 on 库名.表名 to 用户名@"客户端地址" identified by "密码"  with grant option;

详细介绍:

权限列表:select、
		update(字段名,...字段N)(可以更新的字段列表)、
		(drop,delete)(逗号分隔)、
		usage(无权限,哈哈!这个官方怎么想出来的)、
		all(所有命令|权限)
库名.表名:
		mysql.music(mysql库下的music表)、
		mysql.*(mysql库下的所有表)、
		*.*(所有库的所有表)
用户名:root
客户端地址:
		%(所有主机)、	
		192.168.84.%(网段内的所有主机)、
		192.168.84.10(一台主机)、
		localhost(数据库服务器本机)
密码:password
with grant option: 是否有授权的权限,也就是使用grant命令的权限

实例:

grant all on *.* to root@"%" identified by "qwer1234!" ;

实例详解:

授权root用户可以在所有主机登录和对所有库所有表的权限

其他实例:

MariaDB [(none)]> grant all on *.* to mydb@"%" identified by "qwer1234!";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 

有网络访问限制的记得关掉
在这里插入图片描述

对授权用户进行管理

查看及密码修改

select user();  # 查看当前登录用户名以及客户端地址

MariaDB [(none)]> select user(); 
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

show grants;  #显示当前登录用户访问权限
show grants for mydb@"%"; # 查看指定用户的权限

MariaDB [(none)]> show grants; 
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

set password=password("123qwer!"); # 修改当前登录用户的密码

MariaDB [(none)]> set password=password("123qwer!");
Query OK, 0 rows affected (0.00 sec)

修改授权用户的密码,有执行失败的例子:可以理解一下(grant all on *.* to mydb@"%" identified by "qwer1234!";)

MariaDB [(none)]> set password for mydb@"192.168.84.20" =password("123qwer!");
ERROR 1133 (42000): Can't find any matching row in the user table
MariaDB [(none)]> set password for mydb@"192.168.84.10" = password("123qwer!");
ERROR 1133 (42000): Can't find any matching row in the user table
MariaDB [(none)]> set password for mydb@"%" = password("123qwer!"); 

Query OK, 0 rows affected (0.00 sec)

# 删除授权用户,就不执行了(grant all on *.* to mydb@"%" identified by "qwer1234!";)
MariaDB [(none)]> drop user mydb@"%"; 

授权的信息以数据的形式存在mysql软件自带数据库mysql中

user
记录授权用户及权限
db
记录用户对数据库的访问权限
tables_priv
记录用户对数据库表的访问权限
columns_pirv
记录用户对数据库表字段的访问权限

user

在这里插入图片描述
db
在这里插入图片描述
在这里插入图片描述

revoke 撤销权限(命令)

命令格式

revoke 权限列表 on 库名.表 from 用户名@"客户端地址";

root密码忘记怎么办

  1. 停止mysql
  2. 跳过授权表启动mysql
vi /ect/my.conf
[mysqld]
skip-grant-tables
validate_password_policy=0
validate_password_length=1
  1. 修改root密码
    方法一:在这里插入图片描述
MariaDB [(none)]> update mysql.user set authentication_string=password("123456") where host="hostlocal" and user="root";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

方法二(有点哈哈)

[root@centos7 ~]# mysqladmin -hlocalshot -uroot -p password "qwer";
Enter password: 
  1. 启动mysql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值