Oracle 为庆祝 MySQL 30 周年,截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。
从今天开始,将英文题库免费公布出来,并进行解析,帮助大家在一个月之内轻松通过OCP认证。
本期公布试题201~210
试题201:
Choose the best answer.You are using an existing server with a new configuration. MySQL Server
fails to start. Examine this snapshot of the error log:190925 12:49:05 InnoDB:Initializing buffer pool,
size = 3.0G 190925 12:49:05 InnoDB:Completed initialization of buffer poolInnoDB:Error:log
file ./ib_logfile0 is of different size 0 5242880 bytes InnoDB:than specified in the .cnf file 0 26214400
bytes!190925 12:49:05 ERROR Plugin 'InnoDB' init function returned error .190925 12:49:05 ERROR
Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 190925 12:49:05 ERROR Aborting190925
12:49:05 Note /usr/sbin/mysqld:Shutdown complete Which action would allow the server to start?
D)First run mysqld --initialize to refresh the size of ib_logfile. [错误]
B)Create a new ib_logfile0 file of size 26214400. [错误]
A)Execute mysqladmin flush-logs. [错误]
C)Remove ib_logfile0 and ib_logfile1 files from the file system. [正确]
解析
用一台现有服务器,但配置了新的参数。MySQL 服务器启动失败。以下是错误日志的片段:190925 12:49:05 InnoDB: Initializing buffer pool, size = 3.0G
190925 12:49:05 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 26214400 bytes!
190925 12:49:05 ERROR Plugin 'InnoDB' init function returned error.
190925 12:49:05 ERROR Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
190925 12:49:05 ERROR Aborting
190925 12:49:05 Note /usr/sbin/mysqld: Shutdown complete D) 首先运行 mysqld --initialize 以刷新 ib_logfile 的大小。(错误)B) 创建一个大小为 26214400 字节的新 ib_logfile0 文件。(错误)A) 执行 mysqladmin flush-logs。(错误)C) 从文件系统中删除 ib_logfile0 和 ib_logfile1 文件。(正确)关键错误信息:InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 26214400 bytes! 问题原因:ib_logfile0 的实际大小(5242880 字节 = 5MB) 与 配置文件(.cnf)中指定的 innodb_log_file_size(26214400 字节 = 25MB) 不匹配。InnoDB 要求 日志文件大小必须严格匹配配置,否则会拒绝启动。解决方案✅ C) 删除 ib_logfile0 和 ib_logfile1 文件原理:InnoDB 如果发现日志文件不存在,会在启动时 自动创建新的日志文件,并严格按照 innodb_log_file_size 配置的大小生成。删除旧文件后,MySQL 会重新初始化日志文件,避免大小不匹配的问题。
A) mysqladmin flush-logs flush-logs 用于轮换二进制日志(binlog)和慢查询日志,不适用于 InnoDB 日志文件。
B) 手动创建 25MB 的 ib_logfile0 虽然大小匹配,但 InnoDB 要求日志文件必须成对(ib_logfile0 和 ib_logfile1)且内容符合格式,手动创建可能损坏日志结构。
D) mysqld --initialize --initialize 用于 初始化新数据目录,会清空现有数据,不适用于已有数据的服务器。
试题202:
Choose the best answer.Which characters are most commonly used in a SQL injection attack?
D)^ and $ [错误]
C)null (\\0) and newline (\) [错误]
B)< and > [错误]
A)' and \ [正确]
E) + and - [错误]
解析
SQL 注入(SQL Injection)是一种常见的 Web 安全漏洞,攻击者通过在用户输入中插入恶意 SQL 代码,欺骗数据库执行非预期的操作。最常用的 SQL 注入字符✅ A) ' 和 \单引号 ':用于 闭合 SQL 语句中的字符串,例如:SELECT * FROM users WHERE username = 'admin' AND password = 'xxx';攻击者可注入 ' OR '1'='1 绕过登录验证:SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1'='1';反斜杠 \:用于 转义特殊字符,攻击者可利用它破坏 SQL 语句结构。
试题203:
Choose the best answer.Examine these commands, which execute successfully on the ic1
host:mysqlsh> dba.createCluster( 'cluster1' , memberWeight:35) mysqlsh> var mycluster =
dba.getCluster ()mysqlsh> mycluster.addInstance ( 'ic@ic2' , memberWeight:25) mysqlsh>
mycluster.addInstance( 'ic@ic3' , memberWeight:50)Now examine this configuration setting, which
is the same on all nodes:group_replication_consistency=BEFORE_ON_PRIMARY_FAILOVERWhich
statement is true if primary node ic1 fails?
E)Node ic2 becomes the new primary and is ignored until any backlog of transactions is completed.
[错误]
B)Node ic3 becomes the new primary and existing transactions are considered stale and rolled back.
[错误]
C)Node ic3 becomes the new primary and is ignored until any backlog of transactions is completed.
[正确]
A)Node ic2 becomes the new primary and existing transactions are considered stale and rolled back.
[错误]
D)Only two nodes remain so the election process is uncertain and must be done manually. [错误]
解析
选择最佳答案。
观察以下在 ic1 主机上成功执行的命令:mysqlsh> dba.createCluster('cluster1', {memberWeight: 35});
mysqlsh> var mycluster = dba.getCluster();
mysqlsh> mycluster.addInstance('ic@ic2', {memberWeight: 25});
mysqlsh> mycluster.addInstance('ic@ic3', {memberWeight: 50});现在观察所有节点上相同的配置设置:group_replication_consistency=BEFORE_ON_PRIMARY_FAILOVER如果主节点 ic1 宕机,以下哪项描述是正确的?MySQL InnoDB Cluster:基于 Group Replication 的高可用解决方案。memberWeight:用于选举主节点(Primary)的权重值(权重越高,优先级越高)。ic1 = 35ic2 = 25ic3 = 50group_replication_consistency=BEFORE_ON_PRIMARY_FAILOVER:在主节点故障转移时,新主节点必须等待所有未完成的事务应用完毕才能接受写入。2. 主节点选举规则当主节点(ic1)宕机时,集群会根据 memberWeight 选举新主节点。ic3 的权重最高(50),因此会成为新主节点。3. BEFORE_ON_PRIMARY_FAILOVER 的影响新主节点(ic3)在接管前必须:等待所有未完成的事务(backlog)应用完毕。在此期间,ic3 不会立即接受客户端写入(即“被忽略”)。不会回滚事务,只是等待同步完成。E) ic2 成为主节点,并在积压期间被忽略 ❌ 错误 ic3 权重更高,应成为主节点。
B) ic3 成为主节点,事务回滚 ❌ 错误 BEFORE_ON_PRIMARY_FAILOVER 不会回滚事务,而是等待同步。
C) ic3 成为主节点,并在积压期间被忽略 ✅ 正确 符合 BEFORE_ON_PRIMARY_FAILOVER 的行为。
A) ic2 成为主节点,事务回滚 ❌ 错误 ic2 不是权重最高的节点。
D) 选举不确定,需手动干预 ❌ 错误 权重机制确保自动选举。
试题204:
Choose the best answer. You execute this command:shell> mysqlpump --exclude-databases=% -
users Which statement is true?
A)It creates a logical backup of all metadata, but contains no table data. [错误]
D)It creates a logical backup of all MySQL user accounts. [正确]
C)It creates a logical backup of only the users database. [错误]
B)It returns an error because the mysqldump command should have been used. [错误]
解析
shell> mysqlpump --exclude-databases=% --users以下哪项描述是正确的?mysqlpump:MySQL 官方提供的逻辑备份工具(类似 mysqldump,但支持并行备份)。--exclude-databases=%:% 是通配符,表示 排除所有数据库(不备份任何数据库)。--users:仅备份 MySQL 用户账户信息(包括用户名、主机、权限等)。执行该命令后:不会备份任何数据库或表数据(因 --exclude-databases=% 排除了所有库)。仅备份用户账户信息(--users 选项生效),包括:mysql.user、mysql.db、mysql.tables_priv 等权限表的数据。A) 备份所有元数据,不含表数据 ❌ 错误
--exclude-databases=% 排除了所有数据库元数据,仅备份用户信息。D) 备份所有 MySQL 用户账户 ✅ 正确
--users 明确指定备份用户信息。C) 仅备份 users 数据库 ❌ 错误
users 是选项名,非数据库名,且所有数据库已被排除。B) 应使用 mysqldump 导致错误 ❌ 错误
mysqlpump 是合法命令,语法无误。
试题205:
Choose the best answer You want to log only the changes made to the database objects and data
on the MySQL system. Which log will do this by default?
C)error log [错误]
D)general query log [错误]
E)audit log [错误]
A)slow query log [错误]
B)binary log [正确]
解析
B)binary log [正确]二进制日志(Binary Log)功能:记录所有对数据库的修改操作(如INSERT、UPDATE、DELETE、DDL语句),用于主从复制和数据恢复。符合题意:题目描述的“记录更改”正是二进制日志的核心功能。
试题206:
Choose the best answer.Examine this partial output for InnoDB Cluster status:(见下图)Which
statement explains the state of the instance deployed on host2?C)It can be recovered from a donor instance on host3 by cloning using the command
cluster.rejoinInstance ('<user>@host3:3377'). [正确]
B)It has been expelled from the cluster because of a transaction error. [错误]
D)It has been removed from the cluster by using the command STOP GROUP_REPLICATION;. . [错误]
E)It can rejoin the cluster by using the command dba. rebootClusterFromCompleteOutage(). [错误]
A)It can rejoin the cluster by using the command cluster.addInstance ('<user>@host3:3377'). [错误]
解析
InnoDB Cluster 状态分析(图片内容):host1:3377:模式为 R/W(读写),状态 ONLINE(在线)。host2:3377:模式为 R/O(只读),状态 (MISSING)(缺失)。host3:3377:模式为 R/O(只读),状态 ONLINE(在线)。(MISSING) 状态的含义:表示该实例当前未连接到集群,但未被永久移除(可能因网络问题、崩溃或主动退出导致)。需要重新加入(rejoin)或从其他节点恢复。选项分析:✅ C) 可以通过克隆方式从 host3 的捐赠实例恢复,使用 cluster.rejoinInstance()。正确:host2 状态为 (MISSING),但仍属于集群配置的一部分。rejoinInstance() 是专门用于让缺失实例重新加入集群的命令。若数据不一致,可通过克隆(clone)从在线节点(如 host3)同步数据。❌ A) 使用 cluster.addInstance() 重新加入。错误:addInstance() 用于添加全新实例,而 host2 是已存在的实例,应使用 rejoinInstance()。❌ B) 因事务错误被驱逐。错误:(MISSING) 仅表示实例离线,未被明确驱逐(驱逐会显示 EXPELED)。❌ D) 因执行 STOP GROUP_REPLICATION 被移除。错误:手动停止组复制不会导致状态变为 (MISSING),而是显示为 OFFLINE。❌ E) 使用 dba.rebootClusterFromCompleteOutage() 恢复。错误:该命令用于整个集群崩溃后重启,不适用于单个实例恢复。
试题207:
Choose the best answer.You use Row Based Replication and need to see \pseudo-SQL\ statements
for the replication event that is located in the log_file position NNNNN file.Which command should
you use?
H)mysqlshow --verbose --start-position=NNNNN log_file [错误]
F)mysqlbinlog --verbose - - stop-position=NNNNN log_file [错误]
E)mysqlshow --verbose --stop-position=NNNNN log_file [错误]
C)mysqlbinlog --debug --start-position=NNNNN log_file [错误]
B)mysqlbinlog --verbose --start-position=NNNN log_file [正确]
D)mysqlbinlog --debug -- stop-position=NNNNN log_file [错误]
G)mysqlshow --debug --start-position=NNNNN log_file [错误]
A)mysqlshow --debug --stop-position=NNNNN log_file [错误]
解析
--verbose(-v)选项:将行格式的binlog转换为伪SQL语句(--verbose 或 -v 会显示更详细的信息)。
--start-position=NNNNN:指定从哪个日志位置开始解析(题目要求查看“位于NNNNN的事件”)。
试题208:
Choose the best answer.Which utility would you use to view the queries in the slow query log
sorted by average query time?
B)mysqlshow [错误]
C)mysqlimport [错误]
A)mysqlcheck [错误]
E)mysqldumpslow [正确]
D)mysqldump [错误]
解析
mysqldumpslow 是专门用于分析慢查询日志的工具
试题209:
Choose the best answer.Examine the command, which executes successfully:shell> mysqld -
initialize Which statement is true?
D)The root password is not created allowing easy access from the same host. [错误]
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. [错误]
解析
题目:
分析以下命令(该命令执行成功):
shellshell> mysqld --initialize哪一项描述是正确的?选项:
A) root 密码以明文形式生成在错误日志中。 [正确]
B) 安装过程会在 /tmp 目录下创建一个临时的测试环境及数据。 [错误]
C) 安装过程中不会强制执行或生成 SSL 证书。 [错误]
D) root 密码不会被创建,从而允许同一主机轻松访问。 [错误]
中文解析:
关键点:mysqld --initialize 的作用mysqld --initialize(MySQL 5.7+ 的初始化方式):用于初始化一个新的 MySQL 数据目录(如首次安装 MySQL)。不会自动启动 MySQL 服务,仅生成系统表(如 mysql.user)和初始结构。默认情况下,会生成一个随机的 root 密码,并记录在错误日志(error log)中(明文显示)。mysqld --initialize-insecure(不安全模式):如果使用 --initialize-insecure,则 root 密码为空(符合选项 D 的描述)。但题目使用的是 --initialize,所以 D 是错误的。选项分析:✅ A) root 密码以明文形式生成在错误日志中。正确。--initialize 会生成随机密码,并写入错误日志(如 /var/log/mysql/error.log)。❌ B) 安装过程会在 /tmp 目录下创建临时测试环境。错误。--initialize 初始化的是正式的数据目录(如 /var/lib/mysql),而非 /tmp。❌ C) 安装过程中不会强制执行或生成 SSL 证书。错误。SSL 证书是否生成取决于配置(如 auto_generate_certs 参数),但 --initialize 本身不涉及 SSL 管理。❌ D) root 密码不会被创建,允许同一主机轻松访问。错误。--initialize 会生成密码,只有 --initialize-insecure 才会留空密码。
试题210:
Choose the best answer.Your MySQL environment has asynchronous position based-replication
with one master and one slave.The slave instance had a disk I/O problem, so it was stopped.You
determined that the slave relay log files were corrupted and unusable, but no other files are
damaged.You restart MySQL Server.How can replication be restored?
A)The slave relay logs should be deleted; then execute START SLAVE; [错误]
B)The slave needs to be restored from backup. [错误]
C)The slave relay logs should be deleted; execute CHANGE MASTER to adjust the replication relay
log file name, then issue START SLAVE; [正确]
D)The relay logs from the master should be used to replace the corrupted relay logs. [错误]
解析
MySQL 环境采用基于位置的异步复制(asynchronous position-based replication),包含一个主库(master)和一个从库(slave)。
从库因磁盘 I/O 问题被停止运行。你发现从库的中继日志(relay log)已损坏且不可用,但其他文件未损坏。
现在重启 MySQL 服务,如何恢复复制?A) 删除从库的中继日志,然后执行 START SLAVE; [错误]
B) 需要从备份恢复从库 [错误]
C) 删除从库的中继日志,执行 CHANGE MASTER 调整复制中继日志文件名,再执行 START SLAVE; [正确]
D) 使用主库的中继日志替换损坏的从库中继日志 [错误]从库的中继日志(relay log)损坏,但其他文件(如 relay-log.info、master.info)未损坏。
由于复制是基于位置的,只要知道主库的 binlog 位置,就可以重新同步。步骤:删除损坏的中继日志(如 rm /var/lib/mysql/relay-log.*)。执行 CHANGE MASTER,重新指定主库的 binlog 位置(从 relay-log.info 获取):sqlCHANGE MASTER TO MASTER_LOG_FILE='master-bin.XXXXXX', MASTER_LOG_POS=XXXXXX;启动复制:START SLAVE;