MySQL OCP888题解047-skip-grant-tables

1、原题

1.1、英文原题

Which two statements are true about MySQL when it was been started using the --skip-grant-tables option?
A、All users have unrestricted access.
B、All connections succeed regardless the username and password.
C、Only the password for active account can be changed.
D、MySQL becomes read-only except for setting passwords.
E、User authentication is based on the operation system username.

1.2、中文翻译

当MySQL使用–skip-grant-tables选项启动时,哪两条语句是正确的?
A、 所有用户都可以不受限制地访问。
B、 无论用户名和密码如何,所有连接都会成功。
C、 只能更改活动帐户的密码。
D、 MySQL变为只读,设置密码除外。
E、 用户身份验证基于操作系统用户名。

1.3、答案

A、B

2、题目解析

2.1、题干解析

本题主要考察–skip-grant-tables选项。

2.2、选项解析

  1. 使用–skip-grant-tables选项启动MySQL服务器后,会让服务器不读取mysql库的grant表,因此在启动后不再进行认证鉴权。这使得任何有权限进入服务器的人都可以不受限制地访问所有数据库。所以选项A和B正确。
  2. 使用–skip-grant-tables选项启动MySQL服务器后,可以改所有用户的密码,MySQL的所有数据库都可以被任何用户操作,不做任何认证,所以选项C、D、E错误。

3、知识点

3.1、知识点1:skip-grant-tables服务器选项

  • 使用–skip-grant-tables选项启动MySQL服务器后,会让服务器不读取mysql库的grant表,因此在启动后不再进行认证鉴权。这使得任何有权限进入服务器的人都可以不受限制地访问所有数据库。
  • 如果在使用–skip-grant-tables选项启动MySQL服务器后,需要加载授权表实现认证鉴权,可以通过如下方式:
    • 连接服务器执行FLUSH PRIVILEGES语句。
    • 在命令行执行mysqladmin flush-privileges或mysqladmin reload命令。
    • mysql_upgrade升级后也可能会刷新权限。

官方参考文档

4、实验

4.1、实验1

4.1.1、实验目的

验证启动skip-grant-tables是不是所有用户基于各种连接方式都可以登录。

4.1.2、实验前准备

已安装并运行MySQL5.7。

4.1.3、实验步骤

  1. 在一个正常的MySQL中,创建用户d1,设置密码,如下:
mysql> CREATE USER d1 IDENTIFIED BY '111111';
  1. 在Linux本机打开一个新的shell,用u1用户,只要密码正确就可以连接成功:
vm131> mysql -uu1 -p000000
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'u1'@'localhost' (using password: YES)
vm131> mysql -uu1 -p111111
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
  1. 在其他主机上打开shell,用u1用户,只要密码正确就可以连接成功:
vm181> mysql -h192.168.3.131 -P3306 -uu1 -p000000
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'u1'@'192.168.3.181' (using password: YES)
vm181> mysql -h192.168.3.131 -P3306 -uu1 -p111111
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.

4, 修改my.cnf,在[mysqld]中增加skip-grant-tables

[mysqld]
......
skip-grant-tables
......
  1. 重启MySQL服务
vm131> service mysql restart;
  1. 在Linux本机用root可以不带密码登录成功
vm131> mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.40-log MySQL Community Server (GPL)
  1. 在Linux本机用d1用户也可以不带密码登录成功
vm131> mysql -uu1
Welcome to the MySQL monitor.  Commands end with ; or \g.
......
mysql> SELECT user();
+--------+
| user() |
+--------+
| u1@    |
  1. 在其他主机上打开shell,用u1用户,不带密码登录成功:
vm171> mysql -h192.168.3.131 -uu1
Welcome to the MySQL monitor.  Commands end with ; or \g.
......
mysql> SELECT user();
+--------+
| user() |
+--------+
| u1@    |

4.1.4、实验结论

本实验说明,在使用skip-grant-tables启动服务的情况下,所有用户可以通过各种连接方式不受限制的连接。

4.2、实验2

4.2.1、实验目的

验证启动skip-grant-tables后,是不是对数据库只读。验证是不是只能修改本用户的密码。

4.2.2、实验前准备

已安装并运行MySQL5.7。

4.2.3、实验步骤

  1. 在一个正常的MySQL中,先做清理工作,重置测试环境:
mysql> DROP USER IF EXISTS u1;
mysql> DROP USER IF EXISTS u2;
mysql> DROP DATABASE IF EXISTS d1;
mysql> DROP DATABASE IF EXISTS d2;
  1. 创建用户u1,数据库d1、d2,在数据库d1中创建表t1,在d2中创建t2,并插入数据:
mysql> CREATE USER u1 IDENTIFIED BY '111111';
mysql> CREATE USER u2 IDENTIFIED BY '222222';
mysql> CREATE DATABASE d1;
mysql> CREATE DATABASE d2;
mysql> CREATE TABLE d1.t1(id INT);
mysql> CREATE TABLE d2.t2(id INT);
mysql> INSERT INTO d1.t1 SELECT 1;
mysql> INSERT INTO d2.t2 SELECT 2;
  1. 对用户u1授予d1的所有权限,查看用户u1的权限。
mysql> GRANT ALL ON d1.* TO u1;
mysql> SHOW GRANTS FOR u1;
+--------------------------------------------+
| Grants for u1@%                            |
+--------------------------------------------+
| GRANT USAGE ON *.* TO 'u1'@'%'             |
| GRANT ALL PRIVILEGES ON `d1`.* TO 'u1'@'%' |
  1. 使用u1登录
vm131> mysql -uu1 -p111111
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
  1. 用户u1可以对d1和t1做操作,但无权对d2和t2做操作:
mysql> USE d1;
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
mysql> INSERT INTO t1 SELECT 3;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0
mysql> USE d2;
ERROR 1044 (42000): Access denied for user 'u1'@'%' to database 'd2'
mysql> INSERT INTO d2.t2 SELECT 4;
ERROR 1142 (42000): INSERT command denied to user 'u1'@'localhost' for table 't2'
  1. 修改my.cnf,在[mysqld]中增加skip-grant-tables
[mysqld]
......
skip-grant-tables
......
  1. 重启MySQL服务
vm131> service mysql restart;
  1. 用户u1登录以后,不仅可以对t1操作,也可以对d2.t2操作,虽然u1本来没有权限。
vm131> mysql -uu1
Welcome to the MySQL monitor.  Commands end with ; or \g.
mysql> INSERT INTO d1.t1 SELECT 5;
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO d2.t2 SELECT 6;
Query OK, 1 row affected (0.01 sec)
  1. 使用u1,居然发觉可以修改mysql.user表中u2的密码:
mysql> UPDATE mysql.user SET authentication_string=password('000000') WHERE user='u2';
Query OK, 1 row affected, 1 warning (0.01 sec)

4.2.4、实验结论

本实验说明,用skip-grant-talbes选项启动后的MySQL数据库并不是只读的,而且也不是只能修改自己的密码。

5、总结

  1. 使用–skip-grant-talbes选项启动MySQL服务器后,会让服务器不读取mysql库的grant表,因此在启动后不再进行认证鉴权。所有用户在所有客户端上都可以登录MySQL,并且可以操作所有表,更改所有用户的密码。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值