Oracle 为庆祝 MySQL 30 周年,截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。
从今天开始,将英文题库免费公布出来,并进行解析,帮助大家在一个月之内轻松通过OCP认证。
本期公布试题141~150
试题141:
Choose the best answer.You want to dump all databases with names that start with \db\. Which
command will achieve this?
B)mysqlpump --include-databases=db% --result-file=all_db_backup.sql [正确]
C)mysqlpump --include-databases=db -- result-file=all_db_backup.sql [错误]
A)mysqlpump > all_db_backup.sql [错误]
D)mysqlpump -- include-tables-db.% --result-file=all_db_backup.sql [错误]
解析
B) mysqlpump --include-databases=db% --result-file=all_db_backup.sql [正确]
题目解析
题目要求备份所有名称以"db"开头的数据库,正确的命令是使用mysqlpump工具配合--include-databases=db%参数。
试题142:
Choose two.You have an installation of MySQL 8 on Oracle Linux. Consider the outputs:(见下图)
Which statement is true about disk temporary tables for this installation?
B)Temporary tables are created in tmpdir only after they reach tmp_table_size. 不对 [错误]
E)Temporary tables will use the InnoDB temporary tablespace located in /tmp. 参数 innodb_tmpdir
[错误]
A)Only internal temporary tables from the optimizer will be created in tmpdir. tablespace [错误]
D)Temporary tables will use the InnoDB temporary tablespace located in datadir. 参数
innodb_tmpdir [正确]
C)Temporary tables are created in tmpdir only if configured to use MyISAM. [错误]
解析
D) 正确选项解析
存储位置:InnoDB临时表空间默认位于数据目录(datadir)内
文件名称:通常是ibtmp1文件
A) "Only internal temporary tables from the optimizer will be created in tmpdir. tablespace"
错误:优化器创建的内部临时表也可能使用内存或磁盘,不限于tmpdir
B) "Temporary tables are created in tmpdir only after they reach tmp_table_size"
错误:tmp_table_size控制的是内存临时表的最大大小,与存储位置无直接关系
C) "Temporary tables are created in tmpdir only if configured to use MyISAM"
错误:存储引擎选择不影响临时表位置决定逻辑
E) "Temporary tables will use the InnoDB temporary tablespace located in /tmp. 参数 innodb_tmpdir"
错误:临时表空间不在/tmp,innodb_tmpdir是可选参数非默认位置
试题143:
Choose the best answer.What is the correct syntax for using transparent data encryption with an
existing InnoDB table?
C)ALTER TABLE t1 ENCRYPTION='Y'; [正确]
B)ALTER TABLE t1 ADD ENCRYPTED_TABLESPACE = 'Y'; [错误]
D)ALTER TABLE t1 WITH ENCRYPTION USING MASTER KEY; [错误]
A)ALTER TABLE t1 SET TDE = 'ON'; [错误]
解析
C) ALTER TABLE t1 ENCRYPTION='Y'; [正确]
题目询问如何为现有的InnoDB表启用透明数据加密(TDE)的正确SQL语法。
C) 正确选项解析
语法:ALTER TABLE t1 ENCRYPTION='Y';
功能:
启用表空间加密
需要提前配置keyring插件
实际执行表重建操作(类似ALTER TABLE...FORCE)
SELECT TABLE_SCHEMA, TABLE_NAME, CREATE_OPTIONS
FROM INFORMATION_SCHEMA.TABLES
WHERE CREATE_OPTIONS LIKE '%ENCRYPTION%';
A) ALTER TABLE t1 SET TDE = 'ON';
错误:非标准语法,MySQL不使用TDE作为参数名
B) ALTER TABLE t1 ADD ENCRYPTED_TABLESPACE = 'Y';
错误:语法结构错误,ENCRYPTION是表选项非列属性
D) ALTER TABLE t1 WITH ENCRYPTION USING MASTER KEY;
错误:冗余的WITH和USING子句,非标准语法
试题144:
Choose the best answer.You have configured GTID-based asynchronous replication with one master
and one slave. A user accidentally updated some data on the slave.To fix this, you stopped
replication and successfully reverted the accidental changes. Examine the current GTID information:
(见下图)You must fix GTID sets on the slave to avoid replicating unwanted transactions in case of
failover. Which set of actions would allow the slave to continue replicating without erroneous
transactions?
图片地址: https://oss-emcsprod-public.modb.pro/image/exam/question_1640760635659.jpg
E)RESET SLAVE; SET GLOBAL gtid_purged=aaaaaaa-aaa-aaaa-aaa-aaaaaaaa:1-10167; [错误]
D)SET GLOBAL gtid_purged=aaaaaa-aaa-aaa-aaaa-aaaaaaaa:1-2312, bbbbbb-bbbb-bbbb-bbbb
bbbbbbbbbb:1-9; SET GLOBAL gtid_executed=aaaaaaa-aaaa-aaaa-aaaa-aaaaaa:1-10167; [正确]
B)RESET MASTER; SET GLOBAL gtid_purged=aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa:1-10167; [错误]
C)RESET SLAVE; SET GLOBAL gtid_purged=aaaaa-aaa-aaaa-aaaa-aaaaaaaa:1-3820; SET GLOBAL
gtid_executed=aaaaaa-aaaa-aaa-aaaa-aaaaaaaaaaa:1-10300; [错误]
A)RESET MASTER; SET GLOBAL gtid_purged=aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa:1-2312; SET
GLOBAL gtid_executed=aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa:1-10167; [错误]
解析
修复GITD
SET GLOBAL
gtid_purged=aaaaaa-aaa-aaa-aaaa-aaaaaaaa:1-2312,
bbbbbb-bbbb-bbbb-bbbbbbbbbbbbbb:1-9;
SET GLOBAL gtid_executed=aaaaaaa-aaaa-aaaa-aaaa-aaaaaa:1-10167;
[正确]
试题145:
Your my.cnf file contains these settings:mysqldlog_output=FILE slow_query_log
long_query_time=2.01 log_queries_not_using_indexesYou 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?
G)log_throttle_quries_not_using_indexes=5 min_examined_row_limit=5000 [错误]
D)long_query_time=5 log_throttle_quries_not_using_indexes=5 min_examined_row_limit=5000 [错误]
A)log_throttle_queries_not_using_indexes=5 [错误]
C)long_query_time=5 [错误]
F)min_examined_row_limit=5000 [错误]
B)long_query_time=5 log_throttle_queries_not_using_indexes=5 [错误]
E)long_query_time=5 min_examined_row_limit=5000 [正确]
解析
E) long_query_time=5 min_examined_row_limit=5000 [正确]
题目要求配置慢查询日志,记录满足以下条件的查询:
检查了至少5000行记录
执行时间超过5秒 或 没有使用索引
试题146:
Choose the best answer.What does the binlog dump thread do?
D) It reads the relay log and executes the events contained in them. [错误]
A) It monitors and schedules the rotation/deletion of the binary logs. [错误]
C) It acquires a lock on the binary log for reading each event to be sent to the slave. [正确]
B) It connects to the master and asks it to send updates recorded in its binary logs. [错误]
解析
C) It acquires a lock on the binary log for reading each event to be sent to the slave.
中文解析:
Binlog Dump Thread(二进制日志转储线程) 是 MySQL 主从复制(Replication)中运行在主服务器(Master)上的一个线程,它的主要作用是:
锁定二进制日志(Binary Log):在读取事件时,确保日志不会被其他操作修改。
读取二进制日志事件:从主服务器的二进制日志中读取数据更改事件。
发送事件到从服务器(Slave):将这些事件发送给连接的从服务器,以便从服务器重放(Replay)这些操作,保持数据同步。
A) 监控并调度二进制日志的轮换/删除:
这是由 logrotate 或 MySQL 的 expire_logs_days 等机制管理的,而不是 Binlog Dump Thread 的职责。
B) 连接到主服务器并请求发送二进制日志中的更新:
这是从服务器(Slave)上的 I/O Thread 的工作,而不是主服务器上的 Binlog Dump Thread。
D) 读取中继日志(Relay Log)并执行其中的事件:
这是从服务器(Slave)上的 SQL Thread 的工作,与 Binlog Dump Thread 无关。
试题147:
Choose the best answer.You want to check the values of the sort_buffer_size session variables of all
existing connections Which performance_schema table can you query?
A)user_variables_by_thread [错误]
B)global_variables [错误]
C)variables_by_thread [正确]
D)session_variables [错误]
解析
C) variables_by_thread
中文解析:
如果你想查看 所有现有连接(existing connections) 的 sort_buffer_size 会话变量(session variables)的值,应该查询 performance_schema.variables_by_thread 表。
试题148:
解析
题目描述了在 Oracle Linux 上安装 MySQL 并调整 /etc/my.cnf 后,尝试启动 mysqld 服务失败的情况。通过 systemctl status mysqld.service 的输出可以分析失败原因。
C)systemd waited for 30 seconds before timing out and start up failed. [错误]
D)systemd found the mysqld service disabled and failed to start it. [错误]
A)systemd attempted to start mysqld, found another systemd mysqld process running, and shut it
down. [错误]
E)MySQL server was not started due to a problem while executing process 2732. [正确]
B)MySQL server continued to start up even though another process existed. [错误]
关键信息分析:
错误日志显示:
Process: 2732 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS
状态为 code=exited, status=1/FAILURE,说明进程 2732 执行失败。
Main PID: 2732 也显示 exited, status=1/FAILURE,进一步确认 MySQL 启动失败。
A) systemd 尝试启动 mysqld,发现另一个 systemd mysqld 进程正在运行并关闭它
错误。日志中没有提到“另一个进程正在运行”(如 Address already in use 或 PID file exists)。
B) MySQL 服务器继续启动,尽管存在另一个进程
错误。MySQL 启动失败,没有“继续启动”的迹象。
C) systemd 等待 30 秒后超时,导致启动失败
错误。日志中没有超时提示(如 TimeoutStartSec 触发),而是直接显示进程退出失败。
D) systemd 发现 mysqld 服务被禁用,因此启动失败
错误。日志中 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled) 显示服务是 enabled(启用) 的,未被禁用。
正确选项 E:
直接对应日志中的 Process 2732 执行失败(status=1/FAILURE),表明 MySQL 启动因进程执行问题而失败。
可能的原因包括:
/etc/my.cnf 配置错误(如参数冲突或路径无效)。
权限问题(如数据目录不可写)。
端口冲突(但日志未明确提及)。
试题149:
Choose the best answer.You wish to protect your MySQL database against SQL injection attacks.
Which method would fail to do this?
A)using stored procedures for any database access [错误]
D)installing and configuring the Connection Control plugin [正确]
B)avoiding concatenation of SQL statements and user-supplied values in an application [错误]
C)using PREPARED STATEMENTS [错误]
解析
D) installing and configuring the Connection Control plugin
题目问的是 哪种方法无法有效防止 SQL 注入攻击,而 Connection Control 插件 的主要功能是 限制登录失败后的连接频率,并不能防止 SQL 注入。
A) 使用存储过程(Stored Procedures)进行数据库访问
存储过程可以 预编译 SQL,避免直接拼接用户输入,减少 SQL 注入风险。
有效防护手段,但不是绝对安全(如果存储过程内部仍动态拼接 SQL,仍可能被注入)。
B) 避免在应用程序中拼接 SQL 语句和用户输入
最根本的防护方式,使用参数化查询(Parameterized Queries)或 ORM 框架(如 MyBatis、Hibernate)可有效防止注入。
C) 使用预处理语句(Prepared Statements)
预处理语句能有效防止 SQL 注入,因为 SQL 语句和参数分开处理,用户输入不会被当作代码执行。
D) 安装并配置 Connection Control 插件
该插件的作用是防止暴力破解(Brute-Force Attack),例如:
限制某 IP 在多次登录失败后暂时禁止连接。
但它无法阻止 SQL 注入,因为 SQL 注入发生在合法连接建立后的 SQL 执行阶段。
无法防护 SQL 注入,因此是本题的正确答案。
试题150:
Choose the best answer.How can mysql_multi be configured to allow MySQL instances to use the
same port number?
C)The instances use different socket names. [错误]
B)The instances use different user accounts unique teach instance. [错误]
A)The instances listen on different IP addresses. [正确]
D)The instances have appropriate net masks set. [错误]
解析
题目问的是 如何配置 mysql_multi 使多个 MySQL 实例可以使用相同的端口号。关键点在于理解 端口冲突的解决方式。
各选项分析:
A) 实例监听不同的 IP 地址
正确。多个 MySQL 实例可以绑定到不同的 IP 地址(如 192.168.1.100:3306 和 192.168.1.200:3306),即使端口相同也不会冲突。
这是 mysql_multi 支持的标准做法,通过 my.cnf 为每个实例配置 bind-address 指定不同 IP 即可。
B) 实例使用不同的用户账户
错误。MySQL 的运行用户(如 mysql)与端口绑定无关,无法解决端口冲突问题。
C) 实例使用不同的 socket 文件名
错误。Socket 文件(如 /tmp/mysql.sock)仅用于本地连接,不影响 TCP/IP 端口的绑定。多个实例若共用端口仍会冲突。
D) 实例设置适当的网络掩码(net masks)
错误。网络掩码用于子网划分,与 MySQL 实例的端口绑定无关。