MySQL 8.0 OCP 英文题库解析(十七)

发布于:2025-06-13 ⋅ 阅读:(17) ⋅ 点赞:(0)

Oracle 为庆祝 MySQL 30 周年,截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。

从今天开始,将英文题库免费公布出来,并进行解析,帮助大家在一个月之内轻松通过OCP认证。

微信图片_20250507171214.png

本期公布试题151~160

试题151:

Choose the best answer.You plan to upgrade your MySQL 5.7 instance to version 8. You have 
installed the 8 build of MySQL Shell.Examine this command executed from the operating system 
shell prompt:mysqlsh --uri root@localhost:3306 -- util check-for-server-upgrade Which statement is 
true? 
C)It fixes any problems with your 5.7 tables to make them ready to upgrade to 8. [错误] 
A)It documents any problems with your 5.7 tables to make them ready to upgrade to 8. [正确] 
F)It is mandatory to run this command so that MySQL 8.0 software ' s auto-upgrade process has the 
details it needs to operate properly. [错误] 
D)It is mandatory to clear the history of prior results before executing this process a second time or 
later. [错误] 
B)It fails because the operation name must be in camelCase. [错误] 
E)It fails because checkForServerUpgrade must be executed only within an active shell session as a method of the util object. [错误]

解析

您计划将MySQL 5.7实例升级到8.0版本。您已经安装了8.0版本的MySQL Shell。请检查从操作系统shell提示符执行的以下命令:

mysqlsh --uri root@localhost:3306 -- util check-for-server-upgrade

关于这个命令,哪个说法是正确的?

A	它记录 5.7 表的任何问题,使其准备好升级到 8。	✅ 正确。check-for-server-upgrade 是检查工具,仅生成报告,不自动修复问题。
B	它会失败,因为操作名称必须使用驼峰命名法(camelCase)。	❌ 错误。命令中的 check-for-server-upgrade 是合法语法(短横线分隔)。
C	它会修复 5.7 表的任何问题,使其准备好升级到 8。	❌ 错误。该命令仅检查问题,需手动或使用 util upgrade-server 修复。
D	必须清除之前的结果记录才能第二次或后续执行此过程。	❌ 错误。无需清除历史记录,可重复运行。
E	它会失败,因为 checkForServerUpgrade 只能在活跃的 Shell 会话中作为 util 对象的方法执行。	❌ 错误。支持命令行直接调用(如题所示)。
F	必须运行此命令,MySQL 8.0 的自动升级过程才能获取所需信息。	❌ 错误。非强制步骤,但强烈建议检查兼容性。


   

试题152:

Choose the best answer.Your MySQL instance is capturing a huge amount of financial transactions 
every day in the finance database.Company policy is to create a backup every day.The main tables 
being updated are prefixed with transactions-.These tables are archived into tables that are prefixed 
with archives- each month. mysqlbackup --optimistic-busy-tables=\^finance\\. transactions-.*\ 
backup Which optimization process best describes what happens with the redo logs? 
E)The archive tables are backed up first, then the transaction tables and redo logs. [正确] 
D)The transaction tables are backed up first, then the archive tables and redo logs. [错误] 
B)The redo logs are backed up only if there are changes showing for the transactions tables. [错误] 
C)The redo logs are not backed up at all. [错误] 
A)The redo logs are backed up first, then the transaction and archive tables. [错误]

解析

MySQL 实例每天在 finance 数据库中捕获大量金融交易数据。公司政策要求每天执行备份。主要更新的表以 transactions- 为前缀,这些表每月会归档到以 archives- 为前缀的表中。
执行以下备份命令:


mysqlbackup --optimistic-busy-tables=^finance\.transactions-.* backup

关于 redo logs(重做日志)的优化处理,哪一项描述最准确?

A	The redo logs are backed up first, then the transaction and archive tables.	
redo log 最先备份,然后是交易表和归档表。	
❌ 错误。--optimistic-busy-tables 参数针对的是表级备份顺序,未提及 redo log 优先备份。

B	The redo logs are backed up only if there are changes showing for the transactions tables.	
仅当交易表有变更时,redo log 才会被备份。	
❌ 错误。redo log 是事务日志,无论表是否变更都会被备份(除非明确跳过)。

C	The redo logs are not backed up at all.	
redo log 完全不会被备份。	
❌ 错误。MySQL 备份工具(如 mysqlbackup)默认会包含 redo log。

D	The transaction tables are backed up first, then the archive tables and redo logs.	
先备份交易表,然后是归档表和 redo log。	
❌ 错误。--optimistic-busy-tables 仅优化指定表的备份顺序,不改变 redo log 的备份时机。

E	The archive tables are backed up first, then the transaction tables and redo logs.	
先备份归档表,然后是交易表和 redo log。	
✅ 正确。--optimistic-busy-tables 参数指定了 transactions-* 表的备份顺序(非优先),默认情况下,静态表(如归档表)会先备份,动态表(交易表)和 redo log 后备份。

试题153:

Choose the best answer.You must replay the binary logs on your MySQL server. Which command 
do you use? 
A)cat binlog.000003 binlog.000004 binlog.000005 mysql -h 127.0.0.1 [错误] 
D)mysqlbinlog binlog.000003 binlog.000004 binlog.000005 mysql -h 127.0.0.1 [正确] 
C)mysql -h 127.0.0.1 --local-infile binlog.000003 binlog.000004 binlog.000005 [错误] 
B) mysqlpump -h 127.0.0.1 binlog.000003 binlog.000004 binlog.000005 [错误] 
E)mysqlbinlog -h 127.0.0.1 binlog.000003 binlog.000004 binlog.000005 [错误] 

解析

正确答案:D

核心工具:

    mysqlbinlog:解析二进制日志(binlog.00000*)并输出可执行的 SQL 语句。

    管道 (\|):将解析后的 SQL 传递给 mysql 客户端执行。

试题154:

improve the performance of this query:
SELECT Name FROM world.city WHERE Population BETWEEN 1000000 AND 2000000;
Which change enables the query to succeed while accessing fewer rows? 

A)ALTER TABLE world.city ADD INDEX (Name) ; [错误] 
B)ALTER TABLE world.city ADD SPATIAL INDEX (Name) ; [错误] 
C)ALTER TABLE world.city ADD FULLTEXT INDEX (Name) ; [错误] 
F)ALTER TABLE world.city ADD INDEX (Population) ; [正确] 
E)ALTER TABLE world.city ADD SPATIAL INDEX (Population) ; [错误] 
D)ALTER TABLE world.city ADD FULLTEXT INDEX (Population) ; [错误]

图片.png

解析


查询优化

 Population BETWEEN 1000000 AND 2000000;  索引加在条件上,F正确


试题155:

Choose the best answer.Examine this parameter setting:audit_log=FORCE_LOG_PERMANENT What effect does this have on auditing? 
C)It causes the audit log to be created if it does not exist. [错误] 
A)It prevents the audit plugin from being removed from the running server. [正确] 
D)It will force the load of the audit plugin even in case of errors at server start. [错误] 
B)It prevents the audit log from being removed or rotated. [错误]

解析

    正确答案:A

    参数作用:
        FORCE_LOG_PERMANENT 是 MySQL 审计插件(audit_log)的配置选项,确保审计插件在运行时无法被手动卸载,增强审计的强制性和安全性。
        需在 my.cnf 中配置并重启生效。


试题156:

图片.png

A)21 [错误] 
E)20 [正确] 
F)24 [错误] 
C)6 [错误] 
D)22 [错误] 
B)25 [错误]

解析

    SHOW FULL PROCESSLIST 输出:

        连接 22 和 24 的状态为 Waiting for table metadata lock,说明它们在等待元数据锁。

        连接 22 正在执行 OPTIMIZE TABLE test.demo_test(需要元数据锁)。

        连接 24 正在执行 SELECT * FROM test.demo_test(被阻塞)。

    performance_schema.metadata_locks 查询:

        demo_test 表上有 3 个锁:

            SHARED_READ(已授予,线程 ID 60)

            SHARED_WRITE(已授予,线程 ID 60)

            SHARED_NO_READ_WRITE(等待中,线程 ID 62)

        线程 62 持有 INTENTION_EXCLUSIVE 锁(意向排他锁),并正在尝试获取 SHARED_NO_READ_WRITE 锁(但状态为 PENDING,说明被阻塞)。

    performance_schema.threads 查询:

        线程 ID 60 对应连接 ID 20(root 用户)。

        线程 ID 62 对应连接 ID 22(root 用户)。

补充

1. SHARED_READ(共享读锁)

    作用:
    允许并发会话读取表数据,但阻止其他会话修改表结构(如 ALTER TABLE、DROP TABLE)。

    触发场景:

        普通 SELECT 查询(在事务中或隔离级别为 REPEATABLE READ 时持有)。

        LOCK TABLES ... READ 显式加锁。

    兼容性:

        ✅ 与其他 SHARED_READ 锁兼容(允许多个会话同时读)。

        ❌ 与 EXCLUSIVE(排他锁)冲突。

2. SHARED_WRITE(共享写锁)

    作用:
    允许会话修改表数据(如 INSERT/UPDATE/DELETE),但阻止其他会话修改表结构。

    触发场景:

        DML 操作(如 UPDATE test.demo_test SET ...)。

        LOCK TABLES ... WRITE 显式加锁。

    兼容性:

        ✅ 与 SHARED_READ 兼容(读和写可并发)。

        ❌ 与 EXCLUSIVE 或 SHARED_NO_READ_WRITE 冲突。

3. SHARED_NO_READ_WRITE(共享无读写锁)

    作用:
    通常由维护操作(如 OPTIMIZE TABLE、REPAIR TABLE)持有,禁止其他会话读写数据,但允许查询表结构。

    触发场景:

        表维护命令(如 OPTIMIZE TABLE test.demo_test)。

    兼容性:

        ❌ 与所有其他锁冲突(包括 SHARED_READ 和 SHARED_WRITE)。

4. INTENTION_EXCLUSIVE(意向排他锁)

    作用:
    表示会话意图在表上获取排他锁(如 ALTER TABLE),用于快速检测锁冲突。

    触发场景:

        DDL 操作(如 ALTER TABLE test.demo_test ADD COLUMN ...)。

        隐式获取(在请求 EXCLUSIVE 锁前先申请意向锁)。

    兼容性:

        ✅ 与其他意向锁(如 INTENTION_SHARED)兼容。

        ❌ 与 SHARED_READ/SHARED_WRITE 冲突(实际冲突检测在获取排他锁时触发)。


锁类型	   SHARED_READ	SHARED_WRITE	SHARED_NO_READ_WRITE	INTENTION_EXCLUSIVE
SHARED_READ	        ✅	✅	❌	❌
SHARED_WRITE	        ✅	✅	❌	❌
SHARED_NO_READ_WRITE	❌	❌	❌	❌
INTENTION_EXCLUSIVE	❌	❌	❌	✅
实际案例分析(结合题目)

    连接 20(线程 ID 60)持有:

        SHARED_READ + SHARED_WRITE(普通查询或未提交事务)。

    连接 22(线程 ID 62)请求:

        SHARED_NO_READ_WRITE(OPTIMIZE TABLE 需要此锁,但被阻塞)。

    结果:
    OPTIMIZE TABLE 必须等待连接 20 释放锁才能继续。

如何解决锁冲突?

    查看阻塞会话:
    sql

SELECT * FROM sys.schema_table_lock_waits;

终止阻塞会话:
sql

    KILL 20;  -- 终止连接 ID 20

    预防措施:

        避免长事务。

        在低峰期执行 OPTIMIZE TABLE 或 DDL。

开启新对话


    连接 20(线程 ID 60)持有:

        SHARED_READ + SHARED_WRITE(普通查询或未提交事务)。

    连接 22(线程 ID 62)请求:

        SHARED_NO_READ_WRITE(OPTIMIZE TABLE 需要此锁,但被阻塞)。

    结果:
    OPTIMIZE TABLE 必须等待连接 20 释放锁才能继续。

试题157:

Choose the best answerAn attempt to recover an InnoDB Cluster fails. Examine this set of messages 
and responses:host3:3377 ssl JS > dba.rebootClusterFromCompleteOutage () Reconfiguring the 
default cluster from complete outage. . .The instance ' host1:3377' was part of the cluster 
configuration. Would you like to rejoin it to the cluster? y/N :yThe instance ' host2:3377' was part of 
the cluster configuration. Would you like to rejoin it to the cluster? 
y/N :yDba.rebootClusterFromCompleteOutage:The active session instance isn't the most updated in 
comparison with the ONLINE instances of the Cluster's metadata.Please use the most up to date 
instance:' host1:3377'. (RuntimeError) Which statement is true? 

E)The instance deployed on host3 must be rebuilt with a backup from the primary instance. [错误] 
A)The cluster is running and there is at least one ONLINE instance. [错误] 
D)The active session instanceis invalid and must be re-created by using the command shell.connect 
('host3:3377'). [错误] 
C)It is possible to determine the most up-to-date instance by comparing different global 
transaction identifier (GTID) sets with GTID_SUBSET (set1, set2). [正确] 
B)The instance deployed on host3 must be synchronized from a donor deployed on host1 by using 
the command cluster.addInstance('host1:3377'). [错误] 

解析

A	The cluster is running and there is at least one ONLINE instance.	
集群正在运行,且至少有一个 ONLINE 状态的实例。	
❌ 错误。错误提示表明集群处于故障恢复状态,未确认是否有实例在线。

B	The instance deployed on host3 must be synchronized from a donor deployed on host1 by using the command cluster.addInstance('host1:3377').	
host3 上的实例必须通过 cluster.addInstance('host1:3377') 从 host1 的 donor 同步数据。	
❌ 错误。addInstance 用于添加新实例,而非恢复数据同步。正确操作应为 cluster.rejoinInstance() 或基于 GTID 的同步。

C	It is possible to determine the most up-to-date instance by comparing different global transaction identifier (GTID) sets with GTID_SUBSET(set1, set2).	
可以通过 GTID_SUBSET(set1, set2) 比较不同全局事务标识符(GTID)集合来确定最新的实例。	
✅ 正确。GTID 是判断实例数据一致性的关键工具,GTID_SUBSET 可验证事务集的包含关系。

D	The active session instance is invalid and must be re-created by using the command shell.connect('host3:3377').	
当前会话实例无效,必须通过 shell.connect('host3:3377') 重新创建连接。	
❌ 错误。问题根源是实例数据落后,而非会话无效。重新连接无法解决数据不一致问题。

E	The instance deployed on host3 must be rebuilt with a backup from the primary instance.	
host3 上的实例必须通过主实例的备份重建。	
❌ 错误。直接使用 GTID 同步即可,无需重建(除非数据严重损坏)。

试题158:

Examine the command, which execute successfully:shell> mysqld --initialize-insecure Which 
statement is true? 
A)The installation creates a temporary test environment with data in the /tmp directory. [错误] 
B)The installation creates a temporary test environment with data in the /tmp directory. [错误] 
A)The root password is created in the error log in plain text. [正确] 
C)The installation is created without enforcing or generating SSL certificates. [错误] 
D)The root password is not created allowing easy access from the same host. [错误]

解析

A	The installation creates a temporary test environment with data in the /tmp directory.	
安装会在 /tmp 目录下创建一个临时测试环境及数据。	
❌ 错误。--initialize-insecure 初始化的是正式数据目录(默认为 datadir,如 /var/lib/mysql),而非临时目录。

B	The root password is created in the error log in plain text.	
root 密码会以明文形式记录在错误日志中。	
✅ 正确。--initialize-insecure 会生成空密码的 root 账户,并在错误日志中明确提示:
A temporary password is generated for root@localhost: [空密码]。

C	The installation is created without enforcing or generating SSL certificates.	
安装时不强制生成或使用 SSL 证书。	
❌ 错误。SSL 证书的生成与 --initialize-insecure 无关,该参数仅控制账户初始化安全性。

D	The root password is not created, allowing easy access from the same host.	
不创建 root 密码,允许同一主机无密码访问。	
❌ 部分正确但表述不严谨。--initialize-insecure 会创建 root 账户但密码为空(而非“未创建”),允许本地无密码登录,但选项 B 更准确描述日志行为。

    正确答案:B

    --initialize-insecure 的核心行为:

        初始化数据目录(非临时目录)。
        创建 空密码 的 root 账户,并在错误日志中明文记录此状态(如日志提示 A temporary password is generated for root@localhost: [empty])。
        适用于测试环境,生产环境应使用 --initialize 生成随机密码。

    与 --initialize 的区别:
        --initialize:生成随机 root 密码并记录在错误日志中(安全,适合生产)。
        --initialize-insecure:root 密码为空(方便测试,但需手动设置密码后投入使用)。


试题159:

Choose the best answer.You are upgrading a MySQL instance to the latest 8.0 version. Examine this 
output:.(见下图)You plan to add this parameter to the configuration:innodb_directories= ' 
/innodb_extras 'Which statement is true? 

C)It adds more temporary workspace in addition to the innodb_tmpdir location. [错误] 
E)It moves all innodb tablespaces to the /innodb_extras directory to enable a new 
innodb_data_home_dir to be defined. [错误] 
D)It is not necessary because innodb_data_home_dir is already defined. [错误] 
A)It allows scanning of other locations to discover more innodb tablespaces. [正确] 
B)It defines all innodb tablespace options relative to a starting parent directory. [错误] 


解析

A	It allows scanning of other locations to discover more InnoDB tablespaces.	
允许扫描其他位置以发现更多的 InnoDB 表空间。	
✅ 正确。innodb_directories 指定额外的目录,供 InnoDB 在启动时扫描并加载表空间文件(如 .ibd 文件)。

B	It defines all InnoDB tablespace options relative to a starting parent directory.	
定义所有 InnoDB 表空间选项相对于一个父目录。	
❌ 错误。innodb_directories 不用于定义相对路径,而是指定绝对路径供扫描。

C	It adds more temporary workspace in addition to the innodb_tmpdir location.	
在 innodb_tmpdir 之外增加临时工作空间。	
❌ 错误。innodb_directories 与临时文件无关,它用于表空间文件扫描。

D	It is not necessary because innodb_data_home_dir is already defined.	
由于 innodb_data_home_dir 已定义,此参数非必需。	
❌ 错误。innodb_data_home_dir 仅定义默认数据目录,而 innodb_directories 用于扩展扫描位置,二者功能不同。

E	It moves all InnoDB tablespaces to the /innodb_extras directory to enable a new innodb_data_home_dir to be defined.	
将所有 InnoDB 表空间移动到 /innodb_extras 目录,以便定义新的 innodb_data_home_dir。	
❌ 错误。innodb_directories 不会移动文件,仅指定额外扫描路径。



正确答案:A

innodb_directories 的作用:

    指定一个或多个目录,供 InnoDB 在启动时扫描并加载表空间文件(如分离的表空间文件 .ibd)。

    适用于以下场景:

        表空间文件存储在非默认目录(如分布式存储)。

        恢复数据时手动移动了 .ibd 文件到其他位置。

与相关参数的区别:
参数	作用
innodb_data_home_dir	定义默认数据目录(如系统表空间 ibdata1 的路径)。
innodb_directories	指定额外的表空间文件扫描路径(不移动文件)。

试题160:

Choose the best answer.You plan to take daily full backups, which include the ndbinfo and sys 
(internal) databases. Which command will back up the databases in parallel? 
B)mysqlpump --include-databases=% > full-backup-$(date + %Y%m%d).sql [正确] 
C)mysqlpump --all-databases > full-backup-$(date + %Y%m%d).sql [错误] 
D)mysqldump --single-transaction > full-backup-$(date + %Y%m%d).sql [错误] 
A)mysqldump --all-databases > full-backup-$(date + %Y%m%d).sql [错误]

解析

你计划每天进行全量备份,备份需包含 ndbinfo 和 sys(内部)数据库。哪个命令可以并行备份这些数据库?

正确答案:B

核心工具:

    mysqlpump:MySQL 官方工具,支持并行备份(默认线程数=2),适合大规模数据备份。

    --include-databases=%:通配符 % 匹配所有数据库(包括内部库 ndbinfo 和 sys)。

与 mysqldump 对比:
特性	                       mysqlpump	 mysqldump
并行备份	        ✅ 支持(--default-parallelism) ❌ 单线程
通配符匹配库/表	✅(--include-databases)	 ❌ 需显式指定库名
备份速度	        快(并行)	                 慢(单线程)

网站公告

今日签到

点亮在社区的每一天
去签到