10 essential MySQL interview questions

MySQL transaction, we went to the interview question is often asked of advanced development, although many people often use MySQL, SQL statements can also write a very slip, but the interview when asked about these issues, always know where to say play. Let us first look at what is MySQL affairs, give share 10 essential MySQL interview questions.

MySQL transaction is the smallest unit of data processing operations, is a collection operation is not in the division, the operating unit in the series of operations either succeed or fail.

1, MySQL master-slave replication principle.

(1), main library must be turned binary log

(2), when a statement additions and deletions, will be recorded in the main library binlog

(3), the main library by the IO thread binlog contents inside pass relay binlog from the library (relay logs) (This is the reason msyql replication is asynchronous replication)

(4) from the sql thread library is responsible for its relay log in to read the information and apply it to 2, the principle Seconds_Behind_Master database. Sql represents the time between the thread and the thread specific calculation io difference: the time stamp from the current timestamp and the database server binary log events as opposed to get, so the event can be executed only when the reporting delay. Inadequate: some errors (eg max_allowed_packet standby does not match, or network instability) may interrupt copy, because the master-slave replication is asynchronous operation, Seconds_Behind_Master may appear as 03, the main reason for the delay from the master of what?

(1), too slow SQL statements

(2), from the hardware library worse than the primary database

(3), there is too much from a main reservoir under the same library

(4), network delay

(5), excessive partition table (there are a number of reasons, welcome supplement) 4, MySQL storage engines and their common characteristics.

(1), InnoDB supports transactions, row-level locking, support foreign key constraints, mainly OLTP-oriented applications, the use of next-key locking strategies to avoid phantom read phenomenon.

(2), MyISAM does not support transactions, table locks designed to support full-text indexing, write blocking each other, does not support foreign key constraints; mainly for OLAP scenarios; buffer pool cache only the index files, data files are not cached

(3), Memory all data stored in RAM, in the need to quickly find references, and other similar data environment, providing fast access. If the database is restarted or Ben collapse, data will be lost.

(4), TokuDB support services, high compression, told to read and write, design is based on sparse tree index; support most online modify the index, add fields.

(5), Inforbright / infinidb columnar storage, high compression, single query fast 5, innodb_flush_log_at_trx_commit parameters 0, 1 and 2, respectively, represent? innodb_flush_log_at_trx_commit control parameters can be written to update records in the redo log buffer to the log file and log files are flushed to disk operation timing. Once triggered 0 per log buffer written to log file, and the log file flushed to disk. (Due to the process of scheduling problems, can not guarantee 100% per second refresh; if mysql process crashes, you may lose 1s transaction; the highest efficiency, but the most insecure) 1 each commit trigger log buffer is written in the log file and log file flushed to disk. 2 each commit, log buffer is written in a log file; log file flushed to disk per second. (If the operating system crashes or power failure, the transaction may be lost in 1s) 6, Mysql difference in length of varchar, and char CHAR columns when you create a table declared as fixed length range (0-255) VARCHAR column length is not fixed, range (0-65535) 7, meaning (50) 50 represented varchar, meaning int (20) 20 a. varchar (50) 50 on behalf of up to 50 characters can be stored int meanings (20) 20 represents the width of the display, along with 8 zerofill makes sense, meaning several MySQL binlog log entry format for scenes and replication the pros and cons. (1), statement level pattern are each recorded modifies sql data to the binlog master in, slave sql when copying process will resolve to the original master terminal performed the same sql performed again. Application scenarios: from the master data consistency is not too high, and advantages of the scene rarely used function, stored procedures, triggers, etc.: bin-log log less disadvantages: some new features (functions, stored procedures, triggers) synchronization will be obstacles, such as now () (2), row level mode It will be recorded as log data in each row are in a modified form, then the slave terminal further modifications as are suited to the same scene data: master data consistency requirements are relatively high from the scene. Advantages: Detail record disadvantages: the binlog excessive log (3), mixed mode using MySQL default statement recording format of binary log files, but in some cases may use row format, there are possible cases: 1), Table of the NDB storage engine, this time to the table DML operations are recorded in a format ROW 2), using the UUID (), when the USER (), CURRENT_USER (), FOUND_ROWS (), rOW_count () function and other uncertainties 3) using the insert delay statement 4), using the user-defined function (UDF) 5), using the temporary table application scenarios: from the master data consistency is not too high, the scene may be preferably used functions, stored procedures, triggers, etc. 9 interposed disadvantage, redo logs and logs of difference between the binary and the statement row mode (at least three points)

(1) relates to a different storage engine: binlog recording engine operation all storage redo log record only records storage engine innodb log

(2) recorded content is not the same: binlog record is a specific operation details about the transaction. A logical logs and redo log record is the physical circumstances of each page changes

(3) write time is not the same: binlog file only commit before the transaction is committed, that is, only once while writing to disk during the course of the transaction, but there have been redo log entries are written to the redo log file. 10, Explain the implementation of the plan to pay attention to what elements?

(1), type: This type of query table joins, from where you can see about the efficiency of this inquiry

(2), key: the final choice of the index, if the index is not the case, this inquiry are often inefficient

(3), key_len: The actual length of the index query filtered results

(4), rows: expected number of records to be scanned, the expected number of records need to scan small as possible

(5), extra: extra additional information, mainly to confirm whether there Using filesort, Using temporary similar situation

MySQL face more than 10 questions, only one of many MySQL face questions in part personally think it is more typical, relatively high frequency of questions arise, we want to help you!



Guess you like

Origin www.cnblogs.com/waiwei/p/12035576.html