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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章