Oracle 为庆祝 MySQL 30 周年,截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。
从今天开始,将英文题库免费公布出来,并进行解析,帮助大家在一个月之内轻松通过OCP认证。

本期公布试题191~200
试题191:
Consider this shell output and executed commands: root@oel7 ~# ps aux I grep mysqldmysql 2076
3.5 24.6 1386852 372572 ? Ssl 12:01 0:01 /usr/sbin/mysqidroot@oel7 ~ #kill-15 2076Which
statement is true about MySQL server shutdown?
B)kill -15 and kill -9 are effectively the same forced shutdown that risk committed transactions not
written to disk. [错误]
A)ki11 -15 should be avoided. Use other methods such as mysqladmin shutdown or systemct1 stop
mysqld. [错误]
C)kill - 15 carries out a normal shutdown process, such as mysqladmin shutdown. [正确]
D)mysqld_ safe prohibits commands that would harm the operation of the server. An error would
be returned by the kill command. [错误]
解析
考虑以下shell输出和执行的命令:
root@oel7 ~# ps aux | grep mysqld
mysql 2076 3.5 24.6 1386852 372572 ? Ssl 12:01 0:01 /usr/sbin/mysqld
root@oel7 ~# kill -15 2076
关于MySQL服务器关闭,哪个陈述是正确的?
选项:
B) kill -15和kill -9实际上是相同的强制关闭方式,都有已提交事务未写入磁盘的风险 [错误]
A) kill -15应该避免使用,应使用其他方法如mysqladmin shutdown或systemctl stop mysqld [错误]
C) kill -15执行正常关闭过程,类似于mysqladmin shutdown [正确]
D) mysqld_safe会阻止可能损害服务器操作的命令,kill命令会返回错误 [错误]
kill -15 (SIGTERM) 是正常终止信号:
MySQL会执行优雅关闭
完成当前事务
刷新所有数据到磁盘
关闭所有连接
与kill -9 (SIGKILL)的区别:
kill -9是强制终止,不会执行清理操作
kill -15允许MySQL完成必要的清理工作
实际应用建议:
首选mysqladmin shutdown或systemctl stop
kill -15是次优但可接受的替代方案
绝对避免kill -9除非完全必要
其他选项错误原因:
B) 错误,kill -15和kill -9有本质区别
A) 错误,虽然不推荐但kill -15是可接受的
D) 错误,mysqld_safe无法阻止kill命令
试题192:
Choose the best answer.Binary log events for the ‘mydb1’ schema must be copied to a different
schema name ‘mydb2’. Which command will do this?
C)mysqlbinlog --datebase=mydb1 --database=mnydb2 mysql [错误]
D)mysqlbinlog --rewrite-db=‘mydb1’ --rewrite-db=‘mydb2’ mysql [错误]
B)mysqlbinlog --rewrite-db= ‘mydb1->mydb2’ mysql [正确]
A)mysqlbinlog --read- from-remote-server --raw sed ‘s/mydb1/mydb2/g’ mysql [错误]
解析
需要将'mydb1'模式的二进制日志事件复制到另一个模式'mydb2'。哪个命令可以实现这一功能?
选项:
C) mysqlbinlog --datebase=mydb1 --database=mydb2 mysql [错误]
D) mysqlbinlog --rewrite-db='mydb1' --rewrite-db='mydb2' mysql [错误]
B) mysqlbinlog --rewrite-db='mydb1->mydb2' mysql [正确]
A) mysqlbinlog --read-from-remote-server --raw | sed 's/mydb1/mydb2/g' mysql [错误]
正确答案是
B) mysqlbinlog --rewrite-db='mydb1->mydb2' mysql。
解析关键点:
--rewrite-db选项专门用于重写数据库名
语法格式为原数据库名->新数据库名
这会修改二进制日志中的数据库引用
适用于将日志应用到不同名称的数据库
试题193:
Choose the best answer.Examine these entries from the general query log:(见下图)All UPDATE
statements reference existing rows.Which describes the outcome of the sequence of statements?
B)A deadlock occurs immediately. [正确]
A)All statements execute without error. [错误]
D)A deadlock occurs after innodb_lock_wait_timeout seconds. [错误]
C)Connection 25 experiences a lock wait timeout. [错误]
E)Connection 24 experiences a lock wait timeout. [错误]

解析
如果启用了死锁检测(默认),并且发生了死锁,InnoDB 会检测到这个条件并回滚其中一个事务(受害者事务)。
如果使用innodb_deadlock_detect 配置选项禁用了死锁检测,InnoDB 将依赖于
innodb_lock_wait_timeout 设置来在出现死锁时回滚事务
B) 立即发生死锁 [正确]
A) 所有语句执行无错误 [错误]
D) 在innodb_lock_wait_timeout秒后发生死锁 [错误]
C) 连接25经历锁等待超时 [错误]
E) 连接24经历锁等待超时 [错误]
中文解析
正确答案是B) 立即发生死锁。
解析关键点:
死锁条件分析:
连接24锁定了t1表的行(ID=130),尝试锁定t2表的行(ID=3805)
连接25锁定了t2表的行(ID=3805),尝试锁定t1表的行(ID=130)
形成循环等待条件
时间序列:
00:36:27 - 连接24开始事务并锁定t1
00:36:30 - 连接25开始事务并锁定t2
00:36:32 - 连接25尝试锁定t1(被阻塞)
00:36:33 - 连接24尝试锁定t2(被阻塞)
此时立即触发死锁检测
InnoDB处理机制:
自动检测死锁
会回滚其中一个事务(通常选择代价较小的事务)
不是等待超时,而是立即处理
其他选项错误原因:
A) 错误,死锁会导致部分事务回滚
D) 错误,死锁是立即检测的,不需等待超时
C/E) 错误,死锁会优先于锁超时被检测到
试题194:
Choose the best answer.You reconfigure and start a slave that was not replicating for several
days.The configuration file and CHANGE MASTER command are correct.Examine the GTID
information from both master and slave:(见下图)Which statement is true?
C) Replication will fail because the master does not have the required transaction with bbbbbbb
bbbb-bbbb-bbbb-bbbbbbbbbb GTIDs in its binary logs. [正确]
E) Replication will fail because of inconsistent numbers in ccccccc-cccc-cccc-ccccccccccccc GTIDs. [错
误]
A) Replication will fail because the master has already purged transactions with ccccc-cccc-cccc-ccc
cccccccccc GTIDs. [错误]
B) Replication will work. [错误]
D) Replication will fail because the slave has purged more aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa
transactions than the master. [错误]

解析
从服务器的gtids_executed缺少bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb:1-50这个事务集
主服务器的gtids_purged显示已清除bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb:1-10
从服务器需要bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb:11-50的事务,但这些事务已被主服务器清除
C) Replication will fail because the master does not have the required transaction with bbbbbbb
bbbb-bbbb-bbbb-bbbbbbbbbb GTIDs in its binary logs. [正确]
试题195:
Choose the best answerExamine this command, which executes successfully:mysqlbackup -
defaults-file=/backups/server-my.cnf --backup-dir=/backups/full copy-back. Which statement is
true about the copy-back process?
A)It restores files from the data directory to their original MySQL server locations. [错误]
C)The copy-back process is used to overwrite a new backup over an existing backup. [错误]
B)It restores files from the backup directory to their original MySQL server locations. [正确]
D)The copy-back process makes inconsistent backups. [错误]
解析
检查这个成功执行的命令:
mysqlbackup --defaults-file=/backups/server-my.cnf --backup-dir=/backups/full copy-back
关于copy-back过程,哪个陈述是正确的?
选项:
A) 它将文件从数据目录恢复到原始MySQL服务器位置 [错误]
C) copy-back过程用于将新备份覆盖现有备份 [错误]
B) 它将文件从备份目录恢复到原始MySQL服务器位置 [正确]
D) copy-back过程会产生不一致的备份 [错误]
中文解析
正确答案是B) 它将文件从备份目录恢复到原始MySQL服务器位置。
试题196:
Choose the best answer.Your my.cnf file contains these settings:
mysqld log_output=FILE
slow_query_log long_query_time=2.01
log_queries_not_using_indexesY
ou want to log queries that
looked at a minimum of 5000 records and either took longer than 5 seconds to run or did not use indexes.Which contains all the settings that you need to add to or modify the slow log configuration?
D)long_query_time=5 log_throttle_queries_not_using_indexes=5 min_examined_row_limit=5000 [错误]
G)min_examined_row_limit=5000 [错误]
A)log_throttle_queries_not_using_indexes=5 [错误]
E)log_throttle_queries_not_using_indexes=5 min_examined_row_limit=5000 [错误]
C)long_query_time=5 min_examined_row_limit=5000 [正确]
F)long_query_time=5 [错误]
B)long_query_time=5. log_throttle_queries_not_using_indexes=5 [错误]
解析
的my.cnf文件包含以下设置:
[mysqld]
log_output=FILE
slow_query_log
long_query_time=2.0
log_queries_not_using_indexes
您希望记录满足以下条件的查询:
检查了至少5000条记录
且执行时间超过5秒或未使用索引
需要添加或修改哪些慢查询日志配置设置?
正确答案是
C) long_query_time=5 min_examined_row_limit=5000。
试题197:
Choose the best answer.Consider this shell output and executed commands:root@oel7~ # ps aux
grep mysqldmysql 2076 3.5 24.6 1386852 372572 2 Ssl 12:01 0:01 /usr/sbin/mysqldroot@oel7 ~#
kill -15 2076Which statement is true about MySQL server shutdown?
B)mysqld safe prohibits commands that would harm the operation of the server. An error would be
returned by the kill command. [错误]
D)kill -15 should be avoided. Use other methods such as mysqladmin shutdowm or systemctl stop
mysqld. [错误]
A)kill -15 and kill -9 are effectively the same forced shutdown that risk committed transactions not
written to disk. [错误]
C)kill -15 carries out a normal shutdown process, such as mysqladmin shutdown. [正确]
解析
选择最佳答案。考虑以下shell输出和执行命令:
root@oel7~ # ps aux | grep mysqld
mysql 2076 3.5 24.6 1386852 372572 2 Ssl 12:01 0:01 /usr/sbin/mysqld
root@oel7 ~# kill -15 2076
关于MySQL服务器关闭,以下哪项描述是正确的?
选项翻译:
B) mysqld_safe 会阻止可能损害服务器运行的命令。kill 命令会返回一个错误。
(错误)
D) 应避免使用 kill -15。应使用其他方法,如 mysqladmin shutdown 或 systemctl stop mysqld。
(错误)
A) kill -15 和 kill -9 实际上是相同的强制关闭方式,可能导致已提交的事务未写入磁盘。
(错误)
C) kill -15 会执行正常的关闭过程,类似于 mysqladmin shutdown。
(正确)
kill -15(SIGTERM):
通知进程“优雅关闭”,允许其完成未完成的操作(如写入事务、释放资源)。
MySQL 收到此信号后,会执行与 mysqladmin shutdown 相同的正常关闭流程。
kill -9(SIGKILL):
强制立即终止进程,可能导致事务丢失或数据损坏。
选项分析:
A:错误。-15 和 -9 完全不同,-15 是安全关闭。
B:错误。mysqld_safe 是监控进程,但不会阻止 kill -15。
D:错误。kill -15 是安全的,但推荐优先使用 mysqladmin 或 systemctl。
C:正确。kill -15 触发的行为与 mysqladmin shutdown 一致。
试题198:
Choose the best answer.You have a MySQL system with 500 GB of data that needs frequent
backups. You use a mix of MyISAM and InnoDB storage engines for your data.Examine your backup
requirements:·The MySQL system being backed up can never be unavailable or locked to the client
applications.·The recovery from the backup must work on any system.·Only 1 hour of data can be
lost on recovery of the backup. Which option fulfills all backup requirements?
C)Use the Clone Plugin to copy the data to another MySQL system. [错误]
D)Take your backup from a slave of the MySQL system. [正确]
A)Take a physical backup of the MySQL system. [错误]
B)Take a logical backup of the MySQL system. [错误]
解析
选择最佳答案。
你有一个包含 500 GB 数据的 MySQL 系统,需要频繁备份。数据使用了 MyISAM 和 InnoDB 存储引擎。
请检查你的备份需求:
MySQL 系统在备份期间不能对客户端应用程序不可用或锁定。
备份的恢复必须能在任何系统上运行。
恢复备份时最多只能丢失 1 小时的数据。
C) 使用 Clone Plugin 将数据复制到另一个 MySQL 系统。
(错误)
D) 从 MySQL 系统的从库(slave)进行备份。
(正确)
A) 对 MySQL 系统进行物理备份(如 xtrabackup 或直接复制数据文件)。
(错误)
B) 对 MySQL 系统进行逻辑备份(如 mysqldump 或 mysqlpump)。
(错误)
中文解析:
1. 题目需求分析
备份期间不影响主库可用性 → 不能在主库上直接执行锁表操作(如 FLUSH TABLES WITH READ LOCK)。
恢复必须能在任何系统上运行 → 备份必须具有可移植性(逻辑备份或物理备份均可)。
最多丢失 1 小时数据 → 需要支持增量备份或基于复制的实时同步(如主从架构)。
A 物理备份(如 xtrabackup)
❌ 不完全符合
物理备份在主库执行时可能短暂影响性能,且恢复时需要兼容的文件系统/MySQL 版本。
B 逻辑备份(如 mysqldump)
❌ 不符合 逻辑备份会锁表(MyISAM 不支持无锁备份),影响主库可用性。
C Clone Plugin
❌ 不符合 Clone Plugin 会阻塞主库操作,不满足“备份期间不影响可用性”的要求。
D 从从库(slave)备份
✅ 完全符合 - 主库不受影响(备份在从库执行)。
- 可结合逻辑/物理备份。
- 从库可配置 sync_binlog 和 innodb_flush_log_at_trx_commit=1 确保最多丢失 1 小时数据。
其他选项的缺陷
A(物理备份):如果直接在主库执行,可能短暂影响 I/O 性能。
B(逻辑备份):mysqldump 会锁 MyISAM 表,导致主库不可用。
C(Clone Plugin):克隆期间主库会阻塞 DDL 操作,违反“不影响可用性”的要求。
试题199:
Choose the best answer.Which statement is true about InnoDB persistent index statistics?
B)Execution plans based on transient index statistics improve precision when
innodb_stats_persistent_sample_pages is increased. [错误]
D)Setting innodb_stats_auto_recalc=ON causes statistics to be updated automatically when a new
index is created. more than 10% of its rows [错误]
E)Updating index statistics is an I/O expensive operation. [正确]
A)Increasing innodb_stats_persistent_sample_pages determines higher pages scanning speed, at the
cost of increased memory usage. [错误]
C)Index statistics are calculated from pages buffered in the buffer pool for tables with InnoDB
storage engine. [错误]
解析
选择最佳答案。
关于 InnoDB 持久化索引统计信息(persistent index statistics),以下哪项描述是正确的?
选项翻译:
B) 基于临时索引统计信息的执行计划在 innodb_stats_persistent_sample_pages 增加时可以提高精确度。
(错误)
D) 设置 innodb_stats_auto_recalc=ON 会在创建新索引或超过 10% 的行被修改时自动更新统计信息。
(错误)
E) 更新索引统计信息是一项 I/O 密集型操作。
(正确)
A) 增加 innodb_stats_persistent_sample_pages 会提高页面扫描速度,但会增加内存使用量。
(错误)
C) 对于使用 InnoDB 存储引擎的表,索引统计信息是从缓冲池(buffer pool)中的页面计算的。
(错误)
中文解析:
1. InnoDB 持久化索引统计信息(Persistent Index Statistics)
InnoDB 会收集表的索引统计信息,用于优化 SQL 查询的执行计划。这些统计信息可以存储在磁盘(持久化)或内存(非持久化)。
2. 关键参数
innodb_stats_persistent=ON(默认 ON):启用持久化统计信息,存储在 mysql.innodb_index_stats 和 mysql.innodb_table_stats。
innodb_stats_auto_recalc=ON(默认 ON):当表数据变化超过 10% 时自动重新计算统计信息。
innodb_stats_persistent_sample_pages(默认 20):采样页数,影响统计信息的精确度。
3. 选项分析
选项 描述 是否正确? 原因
B 增加 innodb_stats_persistent_sample_pages 可提高执行计划精确度
❌ 错误
该参数影响的是 持久化统计信息(persistent),而非 临时统计信息(transient)。
D innodb_stats_auto_recalc=ON 会在创建索引或修改 10% 数据时更新统计信息
❌ 错误
auto_recalc 仅 在数据修改超过 10% 时触发,不会 在创建索引时自动更新。
E 更新索引统计信息是 I/O 密集型操作
✅ 正确
更新统计信息需要读取数据页(可能涉及磁盘 I/O),特别是 innodb_stats_persistent_sample_pages 较大时。
A 增加 innodb_stats_persistent_sample_pages 会提高扫描速度但增加内存
❌ 错误
增加采样页数会 降低扫描速度(需读取更多页),但 不会显著影响内存(统计信息存储在磁盘)。
C 索引统计信息是从缓冲池中的页面计算的
❌ 错误
统计信息基于 磁盘上的数据页(可能部分在缓冲池),而非仅缓冲池中的页面。
试题200:
Choose the best answer.Which step or set of steps can be used to rotate the error log?
D) Execute SET GLOBAL expire_logs_days=0 to enforce a log rotation. [错误]
B) Rename the error log file on disk, and then execute FLUSH ERROR LOGS. [正确]
C) Execute SET GLOBAL log_error = ' <new error log file> '. [错误]
A) Execute SET GLOBAL max_error_count = <number of messages at point to rotate>. [错误]
解析
下哪一步或哪一组步骤可用于轮换(rotate)错误日志(error log)?
D) 执行 SET GLOBAL expire_logs_days=0 以强制执行日志轮换。
(错误)
B) 重命名磁盘上的错误日志文件,然后执行 FLUSH ERROR LOGS。
(正确)
C) 执行 SET GLOBAL log_error = '<new error log file>'。
(错误)
A) 执行 SET GLOBAL max_error_count = <轮换时的消息数量>。
(错误)
中文解析:
1. MySQL 错误日志轮换(Error Log Rotation)
MySQL 错误日志(error log)记录服务器运行时的错误、警告等信息。默认情况下,MySQL 不会自动轮换错误日志(不像二进制日志 binlog 可以设置 expire_logs_days 自动清理)。
因此,管理员需要 手动轮换错误日志,常见方法包括:
2. 正确方法(选项 B)
✅ B) 重命名错误日志文件,然后执行 FLUSH ERROR LOGS
步骤:
重命名当前错误日志文件(如 mv error.log error.log.old)。
执行 FLUSH ERROR LOGS(或 FLUSH LOGS),MySQL 会关闭旧日志并创建新日志文件。
原理:
MySQL 在运行时保持错误日志文件打开,直接删除或清空文件不会立即生效(Linux 文件系统特性)。
FLUSH ERROR LOGS 强制 MySQL 重新打开日志文件(如果原文件被重命名,则新建一个)。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




