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;