ocp詳解

【dbdao.comMySQL OCP認證專題\】- MySQL 5.6 -OCP 考題講解

===========================第1題============================

1. A simplemaster-to-slave replication is currently being used. The following informationis extracted from the SHOW SLAVE STATUS output: 
Last_SQL_Error: Error 'Duplicate entry '8' for key 'PRIMARY'' on query. Defaultdatabase: 'mydb'.
Query: 'insert into mytable VALUES ('8', 'George')'
Skip_Counter: 0 
Retrieved_Gtid_Set: 38f32e23480a7-32a1-c323f78067fd37821: 1-8
Auto_Position: 1
You execute a "SHOW CREATE TABLE mytable" on the slave: 
CREATE TABLE 'mytable' (
'ID' int(11) NOT NULL DEFAULT '0',
'name' char(10) DEFAULT NULL,
PRIMARY KEY ('ID')
)
The table mytable on the slave contains the following: 

You have issued a STOP SLAVE command. One or more statements are requiredbefore you can
issue a START SLAVE command to resolve the duplicate key error.
Which statement should be used?
A)  SET GLOBAL SQL_SKIP_SLAVE_COUNTER=1
B)  SET GTID_NEXT="CONSISTENCY"; 
    BEGIN; COMMIT; 
    SET GTID_NEXT=" AUTOMATIC’;
C)  SET GLOBALenforce_gtid_consistency=ON
D)  SETGTID_EXECUTED="38f32e23480a7-32a1-c323f78067fd37821 : 9";
E)  SETGTID_NEXT="38f32e23480a7-32a1-c323f78067fd37821 : 9"; 
    BEGIN; COMMIT; 
    SET GTID_NEXT="AUTOMATIC";
--------------------------------------------------------------------

答案:E
分析:此題中使用的Replication是通過GTID實現的,因此
A錯,因此GLOBAL SQL_SKIP_SLAVE_COUNTER=1對使用GTID進行的Replication無效
C錯,因爲GLOBAL enforce_gtid_consistency=ON是實現的前提。
由於GTID_NEXT的有效值爲:
AUTOMATIC / ANONYMOUS / <UUID>:<NUMBER>
因此 B錯
由於Retrieved_Gtid_Set:38f32e23480a7-32a1-c323f78067fd37821: 1-8
因此已經收到主庫事務1-8,因此報錯是從第9個事務重複記錄導致的,很有可能slave上的第8行被人爲錄入了,導致同步問題。
D錯,因爲GTID_EXECUTED表示已經執行完成的事務。
爲了臨時繞過這個問題,使用注入空事務(BEGIN; COMMIT; ) 代替完成第9個事務.完成後GTID_EXECUTED纔會變爲"38f32e23480a7-32a1-c323f78067fd37821 : 9"
這時候重新SET GTID_NEXT="AUTOMATIC"; 重啓slave後,開始從第10個事務開始同步。

1. #GTID需要開啓的參數

gtid_mode = on

enforce_gtid_consistency =1

log_slave_updates   = 1

 

2. gtid = source_id:transaction_id

sorce_id mysql實例的唯一標識,transaction_id是事務的唯一標識

 

3. mysql> select@@server_uuid;

查詢當前mysql實例的uuid

 

4. 使用5.6之前的主從change

change master tomaster_host='127.0.0.1',master_user='rep',master_password='rep',

master_log_file='mysql-bin3306.000001',

master_log_pos=151,/*master_auto_position=1*/;

 

ERROR 1776 (HY000):Parameters MASTER_LOG_FILE, MASTER_LOG_POS, RELAY_LOG_FILE and RELAY_LOG_POScannot be set when MASTER_AUTO_POSITION is active.

當使用 MASTER_AUTO_POSITION參數的時候,MASTER_LOG_FILEMASTER_LOG_POS參數不能使用。

 

5. 使用5.6之後的主從change

mysql> change master tomaster_host='127.0.0.1',master_user='rep',master_password='rep',master_port=3306,master_auto_position=1;

詳見:

https://www.cnblogs.com/zhoujinyi/p/4717951.html

 

6. 跳過複製錯誤:gtid_nextgtid_purged

MySQL5.6之前,只需要執行:

mysql> set globalsql_slave_skip_counter=1;

跳過一個錯誤的事務,就可以繼續進行復制了。但在MySQL5.6之後則不行:

 

show slave status裏的信息裏可以找到在執行Master裏的POS:151

 

Exec_Master_Log_Pos:151

的時候報錯,所以通過mysqlbinlog找到了GTID

 

# at 151

#150810 22:57:45server id 1  end_log_pos 199 CRC320x5e14d88f     GTID [commit=yes]

SET@@SESSION.GTID_NEXT= '4e659069-3cd8-11e5-9a49-001c4270714e:1'/*!*/;

 

mysql> stopslave;

Query OK, 0 rowsaffected (0.01 sec)

 

mysql> setsession gtid_next='4e659069-3cd8-11e5-9a49-001c4270714e:1';  #session裏設置gtid_next,即跳過這個GTID

Query OK, 0 rowsaffected (0.01 sec)

 

mysql>begin;      #開啓一個事務

Query OK, 0 rowsaffected (0.00 sec)

 

mysql> commit;

Query OK, 0 rowsaffected (0.01 sec)

 

mysql> SETSESSION GTID_NEXT = AUTOMATIC;   #gtid_next設置回來

Query OK, 0 rowsaffected (0.00 sec)

 

mysql> startslave;  #開啓複製

Query OK, 0 rowsaffected (0.01 sec)

 

===========================第2題============================

2. Consider thefollowing statement on a RANGE partitioned table: 
ALTER TABLE orders DROP PARTITION p1, p3;
What is the outcome of executing the above statement?
A.Only the first partition (p1) will be dropped as only one can be dropped atany time.
B.All data in p1 and p3 partitions are removed, but the table definitionremains unchanged.
C.A syntax error will result as you cannot specify more than one partition inthe same statement.
D.All data in pi and p3 partitions are removed and the table definition ischanged.
--------------------------------------------------------------------

答案:D
在刪除部分分區後,可以使用show create table查看其定義也一併改變了

參考:
http://dev.mysql.com/doc/refman/5.7/en/alter-table-partition-operations.html

1. 創建範圍分區

root@t0epms 16:01:11[jh_test]> SHOW CREATE TABLE t1\G

***************************1. row ***************************

       Table: t1

Create Table: CREATETABLE `t1` (

  `id` int(11) DEFAULT NULL,

  `year_col` int(11) DEFAULT NULL

) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

/*!50100 PARTITIONBY RANGE (year_col)

(PARTITION p0 VALUESLESS THAN (1991) ENGINE = InnoDB,

 PARTITION p1 VALUES LESS THAN (1995) ENGINE =InnoDB,

 PARTITION p2 VALUES LESS THAN (1999) ENGINE =InnoDB) */

1 row in set (0.01sec)

 

2. 刪除部分範圍分區

root@t0epms 16:01:22[jh_test]> ALTER TABLE t1 DROP PARTITION p0, p1;

Query OK, 0 rowsaffected (0.01 sec)

Records: 0  Duplicates: 0 Warnings: 0

 

root@t0epms 16:01:35[jh_test]> SHOW CREATE TABLE t1\G

***************************1. row ***************************

       Table: t1

Create Table: CREATETABLE `t1` (

  `id` int(11) DEFAULT NULL,

  `year_col` int(11) DEFAULT NULL

) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

/*!50100 PARTITIONBY RANGE (year_col)

(PARTITION p2 VALUESLESS THAN (1999) ENGINE = InnoDB) */

1 row in set (0.00sec)

 

===========================第3題============================

3.You inherit a legacy database system when the previous DBA, Bob, leavesthe company. You are notified that users are getting the following error:
mysql> CALL film_in_stock (40, 2, @count);
ERROR 1449 (HY000): The user specified as a definer ('bob'@'localhost') doesnot exist
How would you identify all stored procedures that pose the same problem?
A.Execute SELECT * FROM mysql.routines WHERE DEFINER='bob@localhost';.
B.Execute SHOW ROUTINES WHERE DEFINER='bob@localhost'.
C.Execute SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE     DEFINER='bob@localhost';.
D.Execute SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='bob' andHOST='localhost';.
E.Examine the Mysql error log for other ERROR 1449 messages.
----------------------------------------------------------------------------------

答案:C 
分析:routines表在庫INFORMATION_SCHEMA下,因此A錯。
可以登陸MySQL後,使用? show命令查看show語法。可知show無routine語句,B錯。


可使用以下命令來查看routines:
pager less; -- 翻頁
select * frominformation_schema.routines\G

 



可知C正確
INFORMATION_SCHEMA.PROCESSLIST表中僅顯示了當前正在運行的線程信息,D錯。
Mysql error log是對報錯信息的記錄,並不會有所有存儲過程的記錄,E錯。

 

===========================第4題============================

4. When designing an InnoDB table, identify an advantage of using the BITdatatype Instead of one of the integer datatypes.
A. BIT columns are written by InnoDB at the head of the row, meaning they arealways the first to be retrieved.
B. Multiple BIT columns pack tightly into a row, using less space.
C.  BIT(8) takes less space than eightTINYINT fields.
D.  The BIT columns can be manipulatedwith the bitwise operators &, |, ~, ^, <<, and >>. Theother integer types cannot.
------------------------------------------------

答案:C
分析:關於數據類型的存儲,可查看http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html
A, B都沒有特別在guide中提到。
BIT(8)大致長度爲1個Byte, 8個tinyint的存儲長度相當於一個bigint了, 請注意並不是說tinyint(8),括號中爲可顯示的長度,由於一個tinyint爲1個Byte,因此8個自然要更長。因此C正確。
D錯,int類型值夜可以進行bit操作符的操作

Manipulated 熟練操作   investigate 調查   interfering干涉

 

===========================第5題============================

5. ROW-based replication has stopped working. You investigate the errorlog file and find the following entries: 
2013-08-27 14:15:47 9056 [ERROR] Slave SQL: Could not execute Delete_rows eventon table test.t1; Can’t find record in ‘t1’, Error_code: 1032; handler errorHA_ERR_KEY_NOT_FOUND; the event’s master log 56_master-bin.000003, end_log_pos851, Error_code: 1032
2013-08-27 14:15:47 9056 [warning] Slave: Can’t find record in ‘t1’ Error_code:1032
2013-08-27 14:15:47 9056 [ERROR] Error running query, slave SQL thread aborted.Fix the problem, and restart the slave SQL thread with “SLAVE START”. Westopped at log ‘56_masterbin.000003’ position 684
Why did you receive this error?
A. The slave SQL thread does not have DELETE privileges to execute on test.t1table.s
B. The table definition on the slave litters from the master.
C. Multi-threaded replication slaves can have temporary errors occurring forcross database updates.
D.  The slave SQL thread attempted toremove a row from the test.t1 table, but the row did not exist.
-------------------------------------------------------------------------------------------

答案:D
分析:報錯中說的非常明確Could not execute Delete_rows event ontable test.t1; Can’t find record in ‘t1’,
這說明slave上這條記錄已經被人爲刪除了,導致Row-BasedReplication進行同步刪除的時候,找不到這條記錄。ABC選項都和此報錯以及所問問題無關。

 

===========================第6題============================

6. mysqldump was used to create a single schema backup;
Shell> mysqldump –u root –p sakila > sakila2013.sql
Which two commands will restore the sakila database without interfering withother running
database?
A. Mysql> USE sakila; LOAD DATA INFILE 'sakila2013.sql';
B. Shell> mysql –u root –p sakila < sakila2013.sql
C. Shell> mysqlimport –u root –p sakila sakila2013.sql
D. Shell> mysql –u root -p –e 'use sakila; source sakila2013.sql'
E. Shell> mysql –u root –p –silent < sakila2013.sql
--------------------------------------------------------------------------------

答案:B
分析:
A錯,load data infile針對的是select ... into oufile輸出的表數據文件,其文件中不含有插入執行語句,僅含有數據。而mysqldump導出的文件包含的數據是以可執行sql語句實現的。
C錯,因此mysqlimport是類似於load data infile語句功能的shell命令行工具,因此對應倒入的文件都應該是非sql語句執行的純表數據文件。
我們看到mysqldump在未使用--database項導出時,並未在文件中使用create database語句。


當導入數據庫dump文件,你需要在命令中指定數據庫名,即usedb_name進入此庫:
shell> mysql db_name < dump.sql
因此B正確
mysql -e 可用於執行語句,但是mysql客戶端語句需要使用分號作爲終止符發給服務端,因此每個語句後都需要使用分號,D錯誤。


如果D爲Shell> mysql –u root -p–e 'use sakila; source sakila2013.sql;' 則正確。
E錯. mysql命令項使用中,短項使用單橫槓,長命令項使用雙橫槓 -silent項應該時候雙橫槓,因此錯。
參考:
http://dev.mysql.com/doc/refman/5.7/en/load-data.html
http://dev.mysql.com/doc/refman/5.7/en/mysqlimport.html
http://dev.mysql.com/doc/refman/5.7/en/mysql.html

woson_wang: D也是對的

回覆

===========================第7題===========================

7. Consider the Mysql Enterprise Audit plugin.
You are checking user accounts and attempt the following query: 
Mysql> SELECT user, host, plugin FROM mysql.users;
ERROR 1146 (42S02): Table ‘mysql.users’ doesn’t exist
Which subset of event attributes would indicate this error in the audit.logfile?
A.

NAME=”Query” 
STATUS=”1146” 
SQLTEXT=”select user,host from users”/>
B.
NAME=”Error” 
STATUS=”1146” 
SQLTEXT=”Error 1146 (42S02): Table ‘mysql.users’ doesn’t exist”/>
C.
NAME=”Query” 
STATUS=”1146” 
SQLTEXT=” Error 1146 (42S02): Table ‘mysql.users’ doesn’t exist”/>
D.
NAME=”Error” 
STATUS=”1146” 
SQLTEXT=”select user,host from users”/>
E.
NAME=”Error” 
STATUS=”0” 
SQLTEXT=”Error 1146 (42S02): Table ‘mysql.users’ doesn’t exist”/>
---------------------------------------------------------

答案:A
分析:
注意:MySQL Enterprise Audit是包含在MySQL企業版中的一個擴展插件,因此如果你在學習時使用的是社區版的MySQL,那你是無法實驗的。
因爲它需要在環境變量plugin_dir對應目錄下存在audit_log.so插件文件。
從選擇答案中可知,Audit log中使用的是舊格式進行的記錄。
由於SQLTEXT僅在NAME爲Query或Execute時,纔會有出現,且NAME不存在Error狀態。因此B,D,E錯。
而SQLTEXT僅存放所使用的SQL語句。而返回的狀態存放在STATUS下,0爲成功,非0爲報錯號,因此A對C錯。
參考:
http://dev.mysql.com/doc/refman/5.7/en/audit-log-plugin.html
http://dev.mysql.com/doc/refman/5.7/en/audit-log-file.html

 

===========================第8題===========================

8. Which query would you use to find connections that are in the samestate for longer than 180 seconds?
A. SHOW FULL PROCESSLIST WHERE Time > 180;
B. SELECT * FROM
INFORMATION_SCHEMA.EVENTS SHERE STARTS < (DATE_SUB(NOW(), INTERVAL180 SECOND));
C. SELECT * FROM
INFORMATION_SCHEMA.SESSION_STATUS WHERE STATE < (DATE_SUB(NOW(),INTERVAL 180 SECOND));
D. SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE TIME > 180;
-------------------------------------------------

答案:D
分析:
你可以使用 help show;命令來查看其語法可知:
SHOW [FULL] PROCESSLIST
此語法後面不可以跟where語句,因此A錯。
INFORMATION_SCHEMA.EVENTS表顯示的是計劃的作業,和連接保持的狀態時間無關,B錯。
INFORMATION_SCHEMA.SESSION_STATUS表顯示的是當前會話的變量及其變量值,和狀態信息無關,C錯。
INFORMATION_SCHEMA.PROCESSLIST顯示了當前的連接情況,狀態,以及狀態保持的時間,實際上show processlist也是查看的這張表,不過直接使用select可以使用where語句,D正確。

參考:
http://dev.mysql.com/doc/refman/5.7/en/information-schema.html

 

 

Intensive 加強的 periodically週期性地 pruning 修剪

===========================第9題===========================

9. A database exists as a read-intensive server that is operating withquery_cache_type =DEMAND.
The database is refreshed periodically, but the resultset size of the queriesdoes not fluctuate.
—-Note the following details about this environment: 
A web application uses a limited set of queries.
The Query Cache hit rate is high.
All resultsets fit into the Query Cache.
All queries are configured to use the Query Cache successfully.
The response times for queries have recently started to increase. The cause forthis has correctly been identified as the increase in the number of concurrentusers accessing the web service.
Based solely on the information provided, what is the most likely cause forthis slowdown at the database level?
A.  The Query Cache is pruning queriesdue to an increased number of requests.
B.  Query_cache_min_res_unit has beenexceeded, leading to an increased performance overhead due to additionalmemory block lookups.
C.  Mutex contention on the Query Cacheis forcing the queries to take longer due to its singlethreaded nature.
D.  The average resultset of a query isincreasing due to an increase in the number of users requiring SQLstatement execution.
---------------------------------------------------------------------------------------------------------

答案:C
分析:這是一個讀密集型數據庫,數據庫會在一段時間後刷新,但是其查詢的結果集大小波動不大。而所有結果集都在QueryCache中,且網頁應用使用一套有限的查詢語句。且Query Cache hit rate很高。
因此A,D錯,請求通過的應用查詢,查詢語句數量有限,結果集都能放在Query Cache中,相同查詢語句的請求不會增多Query Cache中的資源的佔用,因此清理查詢並非主要矛盾。
B也錯,因此Query_cache_min_res_unit設置過大,僅會造成Query Cache中碎片過多。如果請求的結果集都能在Query Cache中,這就和碎片沒什麼關係了。
C正確,儘管官方文檔中未大量解釋Query Cache Mutex爭用問題,在線程運行查詢語句時,會在Query Cache中先獲取Mutex鎖,之後開始查詢匹配的查詢語句和結果集。如果找到後返回結果。
如果未找到匹配,在執行查詢後,需要將查詢語句和結果集插入Query Cache中,這也會需要獲取鎖。儘管這個時間所需非常短,但是在讀密集的情況下,資源爭用會導致線程排隊等待現象。
參考:
http://dev.mysql.com/doc/refman/5.7/en/query-cache.html
http://dev.mysql.com/doc/refman/5.7/en/query-cache-configuration.html

 

1.  query_cache_type = 0,1,2,分別代表了offondemand

如果是1,那麼查詢總是先到查詢緩存中查找,即使使用了sql_no_cache仍然查詢緩存,因爲sql_no_cache只是不緩存查詢結果,而不是不使用查詢結果。

 

如果是2DEMAND。在my.ini中增加一行,query_cache_type=2,重啓mysql服務

 

使用sql_cache查詢時間也一樣,因爲sql_cache只是將查詢結果放入緩存,沒有使用sql_cache查詢也會先到查詢緩存中查找數據

 

2.  mysql使用總內存= global_buffers + all_thread_buffers

 

global_buffers ( 全局內存分配總和) =

innodb_buffer_pool_size-- InnoDB高速緩衝,行數據、索引緩衝,以及事務鎖、自適應哈希等

+innodb_additional_mem_pool_size-- InnoDB數據字典額外內存,緩存所有表數據字典

+innodb_log_buffer_size-- InnoDB REDO日誌緩衝,提高REDO日誌寫入效率

+key_buffer_size --MyISAM表索引高速緩衝,提高MyISAM表索引讀寫效率

+query_cache_size --查詢高速緩存,緩存查詢結果,提高反覆查詢返回效率

+table_cahce -- 表空間文件描述符緩存,提高數據表打開效率

+table_definition_cache-- 表定義文件描述符緩存,提高數據表打開效率

 

all_thread_buffers (會話/線程級內存分配總和)=

max_threads(當前活躍連接數)* (

read_buffer_size -- 順序讀緩衝,提高順序讀效率

+read_rnd_buffer_size-- 隨機讀緩衝,提高隨機讀效率

+sort_buffer_size --排序緩衝,提高排序效率

+join_buffer_size --表連接緩衝,提高表連接效率

+binlog_cache_size-- 二進制日誌緩衝,提高二進制日誌寫入效率

+tmp_table_size -- 內存臨時表,提高臨時表存儲效率

+thread_stack -- 線程堆棧,暫時寄存SQL語句/存儲過程

+thread_cache_size-- 線程緩存,降低多次反覆打開線程開銷

+net_buffer_length-- 線程持連接緩衝以及讀取結果緩衝

+bulk_insert_buffer_size) -- MyISAM表批量寫入數據緩衝

 

3.  內存碎片

query_cache_min_res_unit    查詢緩存分配的最小塊的大小(字節),默認爲4k

query_alloc_block_size    爲查詢分析和執行過程中創建的對象分配的內存塊大小

Qcache_free_blocks    代表內存自由塊的多少,反映了內存碎片的情況

==========================

1)當查詢進行的時候,Mysql把查詢結果保存在qureycache中,但如果要保存的結果比較大,超過query_cache_min_res_unit的值,這時候mysql將一邊檢索結果,一邊進行保存結果,所以,有時候並不是把所有結果全部得到後再進行一次性保存,而是每次分配一塊 query_cache_min_res_unit 大小的內存空間保存結果集,使用完後,接着再分配一個這樣的塊,如果還不不夠,接着再分配一個塊,依此類推,也就是說,有可能在一次查詢中,mysql進行多次內存分配的操作。

2)內存碎片的產生。當一塊分配的內存沒有完全使用時,MySQL會把這塊內存Trim掉,把沒有使用的那部分歸還以重複利用。比如,第一次分配4KB,只用了3KB,剩1KB,第二次連續操作,分配4KB,用了2KB,剩2KB,這兩次連續操作共剩下的1KB+2KB=3KB,不足以做個一個內存單元分配,這時候,內存碎片便產生了。

3)使用flush query cache,可以消除碎片

4)如果Qcache_free_blocks值過大,可能是query_cache_min_res_unit值過大,應該調小些

5query_cache_min_res_unit的估計值:(query_cache_size- Qcache_free_memory) / Qcache_queries_in_cache

 

4.  Query Cache Mutex ????

 

 

==========================第10題===========================

10.  You have a login-path named"adamlocal" that was created by using the mysql_config_editorcommand. You need to check what is defined for this login_path to ensure thatit is correct for you deployment.
You execute this command: 
$ mysql_config_editor print –login-path=adamlocal
What is the expected output of this command?
A.  The command prints all parameters forthe login-path. The password is printed in plain text.
B.  The command prints all parameters forthe login-path. The password is shown only when you 
provide the --password option.
C.  The command prints all parameter forthe login-path. The password is replaced with stars.
D.  The command prints the encryptedentry for the login-path. The is only possible to see if an entry exists.
---------------------------------------------------

答案:C
分析:
mysql_config_editor工具命令用於建立外部登陸文件,一般由mysql客戶端或應用來使用,好處在於登陸時免去輸入登陸密碼,密碼已經被保存在了登陸文件中。在環境變量MYSQL_TEST_LOGIN_FILE未設置的情況下,mysql_config_editor默認文件名爲.mylogin.cnf,且文件保存在執行此命令的用戶home目錄下。
登陸文件建立後,可直接使用以下命令登陸:
shell> mysql --login-path=login-path
當然,--login-path的默認值爲client,因此如果你使用mysql_config_editer set --login-path=client 來進行用戶密碼設置設置,那麼登陸所設用戶的時候,連--login-path也可不用了:
shell> mysql
A, D錯,因爲不管如何,你都看不到密碼的,密碼被加密保存後,使用mysql_config_editorprint會將密碼替代以星號顯示。
B錯,使用mysql_config_editor --help可知在參數項中沒有此--password項,且通過參考文檔可知--password是用於設置密碼而非顯示密碼的。
C正確。

參考:
http://dev.mysql.com/doc/refman/5.7/en/mysql-config-editor.html

 

==========================第11題===========================

11   You are using replication andthe binary log files on your master server consume a lot of disk space.
Which two steps should you perform to safely remove some of the older binarylog files?
A. Ensure that none of the attached slaves are using any of the binary logs youwant to delete.
B.  Use the command PURGE BINARY LOGS andspecify a binary log file name or a date and time to remove unused files.
C.  Execute the PURGE BINARY LOGE NOTUSED command.
D.  Remove all of the binary log filesthat have a modification date earlier than today.
E.  Edit the .index file to remove thefiles you want to delete.
---------------------------------------------------------------------------

答案:AB
分析:
A是必須要保證的,你的刪除的肯定不能正被slave使用啦。
PURGE LOGS語法PURGE { BINARY | MASTER } LOGS { TO'log_name' | BEFORE datetime_expr },所做操作會對.index文件進行自動更新。因此B正確,E錯。
C錯,無此語法。
D錯,具體清理到什麼位置需要按照SHOW SLAVE STATUS來查看,而不是武斷地確定刪除早於今天的binary log文件。
參考:
http://dev.mysql.com/doc/refman/5.7/en/purge-binary-logs.html

 

==========================第12題===========================

12.Which two statements are true about InnoDB auto-increment locking?
A. The auto-increment lock can be a table-level lock.
B.  InnoDB never uses table-level locks.
C. Some settings for innodb_autoinc_lock_mode can help reduce locking.
D. InnoDB always protects auto-increment updates with a table-level lock.
E. InnoDB does not use locks to enforce auto-increment uniqueness.
---------------------------------------------------------------------------

答案:A, C
分析:
auto-increment的AUTO-INC鎖是一個表級鎖,因此A正確,B和E錯誤,。
C正確,根據數據庫參數innodb_autoinc_lock_mode的設置,插入操作會根據模式和所用語句的不同選用相應的鎖。innodb_autoinc_lock_mode = 2的時候,將不使用表級鎖和輕量mutex鎖,不過在基於語句複製(SBR: Statement Based Replication)時,會有交錯序列風險。
參考:
http://dev.mysql.com/doc/refman/5.7/en/innodb-auto-increment-handling.html
http://dev.mysql.com/doc/refman/5.7/en/innodb-auto-increment-configurable.html

1. innodb_autoinc_lock_mode0時的,也就是官方說的traditional級別,該自增鎖是表鎖級別,且必須等待當前SQL執行完成後或者回滾掉纔會釋放,這樣在高併發的情況下可想而知自增鎖競爭是比較大的。

 

2. innodb_autoinc_lock_mode1時的,也就是官方說的consecutive

級別,這時如果是單一的insert SQL,可以立即獲得該鎖,並立即釋放,而不必等待當前SQL執行完成(除非在其他事務中已經有session獲取了自增鎖)。另外當SQL是一些批量insertsql時,比如insert into ...select ...,load data,replace..select..時,這時還是表級鎖,可以理解成退化爲必須等待當前SQL執行完才釋放。

可以認爲,該值爲1時是相對比較輕量的鎖,也不會對複製產生影響,唯一的缺陷是產生的自增值不一定是完全連續的(不過個人認爲這個往往不是很重要,也沒必要根據自增id值來統計行數之類)

 

3. innodb_autoinc_lock_mode設置爲2時,所有insert種類的SQL都可以立馬獲得鎖並釋放,這時的效率最高。但是會引入一個新的問題:當binlog_formatstatement時,這時的複製沒法保證安全,因爲批量的insert,比如insert ..select..語句在這個情況下,也可以立馬獲取到一大批的自增id值,不必鎖整個表,slave在回放這個sql時必然會產生錯亂。我們做個測試驗證複製不是安全的。

 

==========================第13題===========================

13.  Consider the Mysql EnterpriseAudit plugin.
A CSV file called data.csv has 100 rows of data.
The stored procedure prepare_db() has 10 auditable statements.
You run the following statements in the mydb database: 
Mysql> CALL prepare_db();
Mysql> LOAD DATA INFILE '/tmp/data.cav' INTO TABLE mytable;
Mysql> SHOW TABLES;
How many events are added to the audit log as a result of the precedingstatements?
A. 102; top-level statements are logged, but LOAD DATA INFILE is logged as aseparate event.
B. 3; only the top-level statements are logged.
C. 111; top-level statements and all lower-level statements are logged.
D. 12; only top-level statements and stored procedure events are logged.
----------------------------------------

答案:B
分析:
audit.log文件中每個<AUDIT_RECORD>元素代表了一個事件,如客戶連接或關閉連接事件,執行SQL語句等。
僅頂層語句會被記錄下來,存儲程序(如觸發器或存儲過程)中的語句不會被記錄。
命令如LOAD DATA INFILE在進行操作時,其對文件內容進行進行操作的具體細節不會被記錄。
因此,A, C, D錯,B正確。
參考:
http://dev.mysql.com/doc/refman/5.7/en/audit-log-plugin-logging-control.html

 

==========================第14題===========================

14.  You execute the followingstatement in a Microsoft Windows environment. There are no conflicts in thepath name definitions.
C: \> mysqld –-install Mysql56 –-defaults–file=C:\my–opts.cnf
What is the expected outcome?
A. Mysqld acts as an MSI installer and installs the Mysql 5.6 version, with thec:\my-opts.cnf configuration file.
B. Mysql is installed as the Windows service name Mysql56, and uses c:\my-opts.cnfas the configuration file
C. An error message is issued because –-install is not a valid option formysqld.
D. A running Mysql 5.6 installation has its runtime configuration updated withthe server variables 
set in c:\my-opts.cnf.


------------------------------------------

答案:B
分析:
首先mysqld是作爲MySQL服務端主程序來運行的,它並不負責MSI安裝的過程,因此A錯。
通過mysqld --install可以進行Windows服務註冊,同時--defaults-file用於設置啓動服務端時使用的配置文件,B正確。
請注意--install命令項僅存在於Windows版MySQL的mysqld命令中,如果你是在Linux上安裝MySQL是無法找到mysqld對應的--install命令項的。
C錯誤,因爲其對於Windows版的mysqld是有效項。

D錯,因此這命令不是用於安裝時的配置。
參考:
http://dev.mysql.com/doc/refman/5.7/en/windows-start-service.html

 

==========================第16題===========================

16.  What are four capabilities of the mysql client program?
A.  Creating and dropping databases
B.  Creating, dropping, and modifyingtables and indexes
C.  Shutting down the server by using theSHUTDOWN command
D.  Creating and administering users
E.  Displaying replication statusinformation
F. Initiating a binary backup of the database by using the START BACKUP command
--------------------------------------

答案:A,B,D,E
分析:首先我們需要分清楚MySQL和mysql這兩個詞的概念,MySQL是指MySQL整個數據庫和其軟件,而mysql則是其軟件中涵蓋的一個客戶端工具。
本題考的是對這些客戶端工具使用。在使用mysql命令行工具登陸服務端後,可以執行的命令也非常多,比如建立和刪除數據庫,表和索引的增刪改等。
你也可以使用mysql客戶端工具來建立用戶,並進行對用戶的權限和訪問進行管理。當然在Master-Slave Replication的主庫和從庫,你也可以使用showmaster status及show slave status來查看複製的狀態情況。
因此, ABDE都是正確的。
至於關閉MySQL Server,這有多種方式,其中一種是使用mysqladmin客戶端工具shutdown命令來實現的,mysql客戶端工具不負責這事。
而備份,邏輯備份可使用mysqldump 或mysqlpump(從MySQL 5.7.6開始)。而binary backup則可以使用mysqlbackup(如果你的MySQL是企業版的話)或使用copy表文件的方式來進行備份,而不是在mysql命令行工具中鍵入START BACKUP命令。
參考:
http://dev.mysql.com/doc/refman/5.7/en/programs-client.html
http://dev.mysql.com/doc/refman/5.7/en/show-slave-status.html
http://dev.mysql.com/doc/refman/5.7/en/mysqladmin.html
http://dev.mysql.com/doc/refman/5.7/en/backup-methods.html

biotwang且START BACKUP爲MySQL Cluster管理客戶端備份命令,非mysql客戶端程序命令

 

==========================第17題===========================

17.  Assume that you want to knowwhich Mysql Server options were set to custom values. Which two methods wouldyou use to find out?
A.  Check the configuration files in theorder in which they are read by the Mysql Server and compare them with defaultvalues.
B.  Check the command-line optionsprovided for the Mysql Server and compare them with default values.
C.  Check the output of SHOW GLOBALVARIABLES and compare it with default values.
D.  Query theINFORMATION_SCHEMA.GLOBAL_VARIABLES table and compare the result with defaultvalues.

答案:C, D (for MySQL 5.6) C (for MySQL 5.7)
分析;
MySQL Server配置項由多處設置組成,由於Server的主程序爲mysqld,因此其命令項設置也主要是看mysqld對應的項的設置。
在命令項設置後,啓動後相應項反應在數據庫上,就是那些Global Variables全局變量了,當用戶會話訪問時,其Session Variables則會copy自全局變量值,之後用戶可以根據需要使用SET命令來修改會話變量。
當然如果有足夠的權限,用戶也可以修改全局變量,不過這種修改僅應用於正在運行MySQL Server,且對之後新登陸會話有效,一旦Server重啓就打回原形了。
此題中,主要是希望查看啓動後,使用的全局變量和其默認值修改情況,一般在啓動初始化時,我們可以提前通過mysqld的命令行項上直接修改,或使用配置文件來進行啓動時候的項的默認修改。
但是A, B都是錯的,因爲你無法確認MySQL Server的全局變量在啓動後是否有人爲被再次修改過。
C正確,因爲show global variables可以瞭解當前所有全局變量值,從而和默認值進行比較。請注意:show variables指的是查看當前會話變量,因此一定要加上global。
D在MySQL 5.6版本中正確,因爲其globalvariables值存放於此表中。不過在5.7版本,GLOBAL_VARIABLES這張表被移至performance_schema下,原先INFORMATION_SCHEMA.GLOBAL_VARIABLES將成爲空表並被棄用。
參考:
http://dev.mysql.com/doc/refman/5.7/en/option-files.html
http://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html

 

==========================第18題===========================

18. You install a copy of Mysql 5.6.13 on a brand new Linux server byusing RPM packages. The server starts successfully as verified by the followingcommands: 
$ pidof mysqld
3132
$ tail – n2 /var/lib.mysql/hostname.err
2013-08-18 08:18:38 3132 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.6.13-enterprise-commercial-advanced' socket: '/tmp/mysql.sock'port: 3306
Mysql Enterprise Server – Advanced Edition (Commercial)
You attempt to log in as the root user with the following command: 
$ mysql –u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:NO)
Which statement is true about this scenario?
A. The RPM installation script sets a default password of password for new installations.
B. The local root user must log in with a blank password initially: mysql –uroot –p.
C. New security measures mean that the mysql_secure_installation script must berun first on all new installations.
D. The mysql_install_db post-installation script used –-random-passwords.
--------------------------------------

答案:D
分析:
MySQL5.6 Linux RPM包安裝中會調用帶有--random-passwords參數項的mysql_install_db腳本命令, 爲root用戶生成一個隨機密碼,並保存在$HOME/.mysql_secret文件中。
A錯,生成的是一個隨機密碼,而非默認密碼。B錯,因爲本地root用戶已經有一個生成的密碼了,因此空密碼是不能登陸成功的。
C錯,mysql_secure_installation是一個非必要腳本,在MySQL安裝完成後,你可以運行此腳本來進一步增強其安全策略。
參考:
http://dev.mysql.com/doc/refman/5.6/en/linux-installation-rpm.html
http://dev.mysql.com/doc/refman/5.6/en/mysql-secure-installation.html

 

==========================第19題===========================

19. A Mysql Server has been running an existing application successfullyfor six months.
The my.cnf is adjusted to contain the following additional configuration:
[mysqld]
default-authentication-plugin=sha256_password
The Mysql Server is restarted without error.
What effect will the new configuration have in existing accounts?
A. They will have their passwords updated on start-up to sha256_password format
B. They will have to change their password the next time they login to theserver
C. They are not affected by this configuration change
D. They all connect via the secure sha256_password algorithm without anyconfiguration change.
-----------------------------

答案:C
分析:
default-authentication-plugin的作用是爲了在create user時默認其所使用的密碼加密格式。其和已經建立的用戶所使用的密碼格式無關,因此A,B錯。
在客戶端工具進行連接時,服務端會在mysql.user表中進行匹配,以瞭解對應登陸用戶所使用的密碼格式,並以此授權方式進行登陸驗證,因此D錯。
參考:
http://dev.mysql.com/doc/refman/5.6/en/sha256-authentication-plugin.html

 

==========================第21題===========================

21.  What are three actions performed by the mysql_secure_installationtool?
A. It prompts you to set the root user account password.
B. It checks whether file permissions are appropriate within datadir.
C. It asks to remove the test database, which is generated at installationtime.
D. It can delete any anonymous accounts.
E.  It verifies that all users areconfiguration with the longer password hash.

答案:ACD
分析:mysql_secure_installation腳本工具僅可做以下四件事:
1. 設置root用戶密碼
2. 去除root用戶的非本地訪問賬號
3. 去除匿名用戶賬號
4. 去除test數據庫。
參考:http://dev.mysql.com/doc/refman/5.6/en/mysql-secure-installation.html

 

==========================第22題===========================

22. Consider the query: 
Mysql> SET 
@run = 15;
Mysql> EXPLAIN SELECT objective, stage, COUNT(stage)
FROM iteminformation
WHERE run=@run AND objective='7.1'
GROUP BY objective,stage
ORDER BY stage;

The iteminformation table has the following indexes; 
Mysql> SHOW INDEXES FROM iteminformation: 

This query is run several times in an application with different values in theWHERE clause in a growing data set.
What is the primary improvement that can be made for this scenario?
A.  Execute the run_2 index because ithas caused a conflict in the choice of key for this query.
B.  Drop the run_2 index because it hascaused a conflict in the choice of key for this query.
C.  Do not pass a user variable in theWHERE clause because it limits the ability of the optimizer to use indexes.
D.  Add an index on the objective columnso that is can be used in both the WHERE and GROUP BY operations.
E. Add a composite index on (run,objective,stage) to allow the query to fullyutilize an index.

答案:E
分析:首先我們需要了解EXPLAIN命令執行後的輸出含義,對應查詢中Possible_Keys顯示在查詢時可使用Run和Run_2這兩個索引來優化查詢,Keys列則表明最終執行計劃選擇使用Run_2索引。
通過SHOW INDEXES FROM <table>命令,我們可以瞭解此表所有的索引,這裏我們知道有Run(Run, Name)索引和Run_2(Run Stage)索引。
MySQL建立的聯合索引,在利用這些索引時,你需要遵循leftmost prefix index(最左前綴索引)原則,即當你有一個索引爲(col1, col2, col3),在查詢時,查詢條件中對(col1), (col1,col2)或(col1, col2, col3)
進行查詢時可以使用到此索引。
由於Where中有run=@run,因此,索引Run和Run_2都滿足被利用的條件,由於GROUP BY按規則無法利用這些索引,而ORDER BY則可以進一步利用stage索引,因此最終優化器選擇使用Run_2索引。
A, B錯,因此這種衝突說法不成立,因爲索引的選擇是由優化器選擇的結果。C錯,使用變量並不會對優化器使用索引進行限制。
D錯,因此僅對objective列建立索引,並不會被GROUPBY使用。
E正確,因爲建立(run,objective,stage)索引,此查詢滿足GROUP BY的Tight Index Scan規則,可以使用此索引提高查詢性能。

參考:
http://dev.mysql.com/doc/refman/5.6/en/explain-output.html
http://dev.mysql.com/doc/refman/5.7/en/show-index.html
http://dev.mysql.com/doc/refman/5.6/en/group-by-optimization.html
http://dev.mysql.com/doc/refman/5.6/en/order-by-optimization.html

 

==========================第23題===========================

23. Consider typical High Availability (HA) solutions that do not useshared storage.
Which three HA solutions do not use shared storage?
A.  MySQL Replication
B.  Distributed Replicated Block Device(DRBD) and Mysql
C.  Windows Cluster and MySQL
D. Solaris Cluster and MySQL
E.  MySQL NDB Cluster

答案:A, B, E
分析:從圖中的Shared Nothing我們就可以知道MySQLReplication,MySQL Fabric,DRBD,MySQL Cluster都符合要求,既然什麼都不會共享使用,那麼存儲也一樣不會被共享啦。


Windows Cluster和Solaris Cluster都類似於第二,三張圖所示,是共享存儲的,因此CD被排除。






MySQL Replication故名思意是複製,複製一個備庫存儲。DRBD是在系統級別的同步複製技術,數據庫是不共享的。
而MySQL NDB Cluster可以通過不同節點組來分散數據達到不共享存儲的目的的,如第四張圖。

參考:
http://dev.mysql.com/doc/refman/5.7/en/replication.html
http://dev.mysql.com/doc/refman/5.7/en/ha-overview.html

==========================第24題===========================

24.  Which three statements arecharacteristic of the MEMORY storage engine?
A.  Each table is represented on disk asan .frm file.
B.  Each table has a corresponding.MYIand .MYD file.
C.  It can support foreign keys.
D.  It cannot contain text or BLOBcolumns.
E.  Table contents are not saved if theserver is restarted.
F.  It can support transactions

答案:A, D, E
分析:以MEMORY引擎建立的每張表都對應了一個以.frm爲後綴的表定義文件。.MYI和.MYD對應的是以MyISAM引擎建立的的表的索引及數據文件。
MEMORY引擎不支持外鍵,不支持事務,也不支持TEXT和BLOB類型列。表會在服務端重啓時被清空,一般作爲臨時工作及從其他表抽取的只讀數據存放地處理。

參考:
http://dev.mysql.com/doc/refman/5.6/en/memory-storage-engine.html

==========================第25題===========================

25.Consider the MySQL Enterprise Audit plugin.
The following event detail is found in the audit log: 
<AUDIT_RECORD
TIMESTAMP="2013-04-09t01:54:17"
NAME="Connect"
CONNECTION_ID="3"
STATUS="1045"
USER="kate"
PROXY_USER=""
HOST="localhost"
IP=""
DB=""/>
Which two points can be concluded from the given event?
A. A connection was blocked by a firewall or a similar security mechanism.
B. A connection was attempted via socket rather than TCP.
C. A connection failed because the proxy user privileges did not match thelogin user.
D. A connection as the user kate was successful.
E. A connection failed due to authentication being unsuccessful.

答案:B, E
分析:
首先對於localhost的本地連接,是使用socket連接方式,因此B正確。
STATUS爲1045,通過perror我們可以知道,報錯爲訪問授權錯誤,說明可能登陸密碼輸入錯誤,這和防火牆沒有關係,因此A錯,E正確。


C錯,PROXY_USER爲空值,索引請登陸並未使用proxyuser。
D錯,STATUS爲1045,因此訪問是失敗的,執行報錯。
參考:
http://dev.mysql.com/doc/refman/5.7/en/connecting.html
http://dev.mysql.com/doc/refman/5.7/en/audit-log-file.html
http://dev.mysql.com/doc/refman/5.7/en/proxy-users.html

 

Perror 1045

 

========================第27題====================

27. You are having problems with connections from a specific host(192.168.1.15) not closing down correctly. 
You want to find the state of the threads from that host check for long-runningqueries.
Which statement will accomplish this?
A. SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE HOST='192.168.1.15';
B. SELECT * FROM INFORMATION_SCHEMA.EVENTS WHERE HOST='192.168.1.15';
C. SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE HOST='192.168.1.15';
D. SELECT * FROM INFORMATION_SCHEMA.INNODB_METEICS WHERE HOST='192.168.1.15';

答案:A
分析:
INFORMATION_SCHEMA.PROCESSLIST提供了正在運行線程的相關信息
INFORMATION_SCHEMA.EVENTS此表存放關於計劃調度事件信息
INFORMATION_SCHEMA.STATISTICS此表存放數據庫表索引信息
INFORMATION_SCHEMA.INNODB_METRICS存放InnoDB性能相關信息
參考:
http://dev.mysql.com/doc/refman/5.6/en/processlist-table.html
http://dev.mysql.com/doc/refman/5.6/en/events-table.html
http://dev.mysql.com/doc/refman/5.6/en/statistics-table.html
http://dev.mysql.com/doc/refman/5.6/en/innodb-metrics-table.html

28.  Identify a performance impactwhen using the Performance Schema.
A.  There is no impact on performance.
B.  There is an overhead for querying thePerformance Schema but not for having it enabled.
C.  There is a constant overhead regardlessof settings and workload.
D.  The overhead depends on the settingsof the Performance Schema.

答案:D
分析:A錯,啓用performance shema會對系統性能進行監控並進行事件記錄,因此這些功能自然會帶來一些額外的開銷,這樣會對性能有一定的影響,不過和用來進行性能分析和診斷的好處相比,這些開銷又是值得的。
當啓動performance schema, 相應的一些默認的instruments也會被啓用,所以B錯。
C錯,D正確,根據你啓用的instruments多少,相應的開銷會有不同,這取決於你的設置。
參考:
http://dimitrik.free.fr/blog/archives/2013/07/mysql-performance-why-performance-schema-overhead.html
http://dev.mysql.com/doc/refman/5.7/en/performance-schema.html

 

29. Which statement is true about FLUSH LOGS command?
A.  It requires the RELOAD, FILE, andDROP privileges.
B.  It closes and reopens all log files.
C.  It closes and sends binary log filesto slave servers.
D.  It flushes dirty pages in the bufferpool to the REDO logs.

答案: B
分析:A錯,FLUSH 語法必須要有RELOAD權限,除此之外針對特定FLUSH語法還會要求有SELECT及LOCK TABLES權限。
B正確,默認在不指定何種日誌的情況下,會對所有日誌進行關閉並開啓新的日誌。
C錯,此語句並不會將binary log發送到slave服務端。
D錯,對於innoDB引擎支持的表,FLUSH TABLES會將dirty pages從buffer pool中刷出到表數據文件中。
參考:
http://dev.mysql.com/doc/refman/5.7/en/flush.html

 

30.Which two are correct steps in taking a binary backup of MyISAM tables?
A.  Always stop the server prior to thebackup.
B.  Stop the server or lock the tablesprior to the backup.
C.  Stop the server or lock the databasesprior to the backup.
D.  Make a copy of the .frm, .myd, andthe .myi files.
E.  Make a copy of the binary log andtablespace files.

答案: B.D.
分析:對於MyISAM引擎的表的binary備份,你可以先使用以下命令鎖表:
FLUSH TABLES tbl_list WITH READ LOCK;
然後拷貝對應表的.frm,.myd和.myi文件來進行備份。因此A,C錯,因爲沒有必要。E錯,因爲這是針對InnoDB引擎的表說的。
參考:
http://dev.mysql.com/doc/refman/5.6/en/backup-methods.html
 

發佈了29 篇原創文章 · 獲贊 10 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章