Road surface MySQL 21 frequency and analytical questions

Road surface MySQL 21 frequency and analytical questions
Q1: MySQL What are the main storage engines, which are suitable for application scenarios?

A: There are ①MyISAM, before the default storage engine version 5.5, supports table-level locking, and foreign keys does not support transactions, concurrency is lower efficiency, fast read data, update data slowly. Mainly adapted to read operations, and the lower concurrency requirements of applications. ②InnoDB, MySQL is currently the default storage engine supports row-level locking, transactions, and foreign keys, good concurrent efficiency. Suitable for transaction integrity and concurrency, data accuracy requirements are relatively high, additions and deletions many operational applications. ③Memory, all data stored in memory, access speed, data will be lost once the service is shut down. Updated less frequently for a small amount of data tables to quickly get access to the results. ④Archive, Federated and so on.

Q2: What indexes are?

A: MySQL official definition of the index is: index (index) is to help MySQL efficiently get the data structure of the data (ordered). In addition to the data, the database system also maintains a data structure to meet specific search algorithm, the data structure reference (point) data in some way, so that you can implement advanced search algorithms on that data structure, this data structure is indexed .

Q3: What are the advantages and disadvantages of the index?

A: ① advantages: improve data retrieval efficiency, reduce costs IO database. Sort the data by the column index, reduce the cost of sorting data, reduce the consumption of CPU. ② disadvantage: in fact, the index is a table, the table holds the primary key and index fields, and points to the record entity class, so the index column is to take up space. Although the index greatly improve query efficiency, but also reduce the speed of updating the table, such as table INSERT, UPDATE, DELETE. Because when you update table, MySQL is not only to save the data, but also save about index file is updated each time adding a field index column will adjust because the index information of the key changes brought about by the update.

Q4: MySQL index, which has several support?

A: ①BTREE Index: The most common type of index, the index most support B-tree indexes. ②HASH Index: Only Memory engine support, the use of simple scenarios. ③R-tree index (spatial index): spatial index is a special index of MyISAM engine type, mainly used for geospatial data types, less commonly used, do not do special presentations. ④Full-text (full-text indexing): a full-text index is a special index type MyISAM, mainly for full-text indexing, InnoDB from Mysql5.6 version began to support full-text indexing.

Q5: B + tree and B-tree is what What is the difference?

A: ①BTree also known as multi-channel balanced search trees, BTree characteristics of a fork m as follows: Each node in the tree contain up to m children. In addition to the root node and leaf nodes, each node has at least [ceil (m / 2)] children. If the root is not a leaf node, then there are at least two children. All leaf nodes are at the same level. Each non-leaf node key by n and n + 1 pointers, where [ceil (m / 2) -1] <= n <= m-1. ②B + Tree is BTree variant, B + Tree BTree differs as follows: n fork B + Tree containing up to n key, and BTree contain up to n-1 th key. B + Tree leaf node maintains all key information, key arrangement according to size. All non-leaf nodes can be seen as a key part of the index. ③ As the only saving B + Tree leaf node key information, inquiries have come from the leaves of any key root. So B + Tree of query performance more stable.

Q6: MySQL B + tree index on what had been done to optimize?

A: MySql index data structure of the classic B + Tree is optimized. On the basis of the original B + Tree, adding a node to the list pointer adjacent leaf, it is formed with a sequence of pointers B + Tree, improve the performance of the access interval.

Q7: What are index classification?

A: ① single-valued index: the index contains only a single column, a table can have multiple separate index. ② unique index: the index column value must be unique, but allow free value. ③ composite index: the index comprises a plurality of columns.

Q8: What created the index database design principles?

A: ① high query frequency, large amount of data tables create the index. ② limit the number of index: For more additions and deletions to change the operating table, if too many indexes will require high maintenance costs, reduce operating efficiency, increase the time-consuming operation. ③ use of the most left-prefix: If the index field value is too long, the index will reduce the efficiency of the implementation. ④ delete the index is not commonly used. ⑤ use a unique index, the higher the discrimination, the higher the efficiency. ⑤ use short index, if the index value is long occupied disk becomes large, it will affect the efficiency. ⑥ as often as the query conditions, often need sorting, grouping and joint field operations indexing. ⑦ try to extend existing indexes, index joint efficient than multiple independent indices.

Q9: index under what circumstances would fail?

A: ① when the composite index is not the leftmost column index use or failure to use the jump, for example, name, age and sex indexing field, using only age and sex or failure when using only the index name and sex. ② When the failure index operation or function carried out operations in the index. ③ numeric characters no single quotes index fail, because MySQL query optimizer will automatically type conversion. ④LIKE to check index% at the beginning of the failure of the implementation of the previous plan% more inclined to use full table scan. Before and after ⑤OR not simultaneously use the index when the index failed. ⑥ When the full-table scans use a full table scan speed is faster than using the index.

Q10: Three paradigms outlined database

A: ① The first paradigm: minimum data unit if each column is not be divided, the first normal form. For example address: China Beijing be split into two, countyr: China, city: Beijing. ② The second paradigm: the paradigm on the basis of a first, predetermined non-primary key of the table columns depend in part on the absence of the primary key, i.e. the second paradigm requires only thing described in each table. For example order form: order number, product number, order date, the price is split into the order form: order number, order date and Products tables: product number, product price. ③ Third Pattern: meet the first and second paradigm, and the column of the table depend on the absence of transmission of non-primary key column. For example order form: order number, order date, user ID, user name can be optimized for the order form: order number, order date, user name.

Q11: MySQL database isolation level of what? What are the characteristics?

A: ① read uncommitted, reads a transaction to another transaction did not submit the data, there are dirty reads, non-repeatable read, phantom read problems. ② read committed, a transaction can read data from another transaction has committed to solve the problem of phantom read, there is a non-repeatable read, phantom read problems. ③ repeatable read, MySQL default isolation level, read in a single transaction with a data result is the same, to solve the problem of non-repeatable read, phantom read problem exists. ④ serialization, each read are required to obtain a shared table-level locking, write blocking each other, inefficiency, read magic to solve the problem.

Q12: What problems might arise when reading the database?

A: ① dirty reads, a transaction reads data to another transaction has not yet submitted the final transaction is rolled back if the other data, then the read data is invalid. ② non-repeatable read, a transaction can read data from another transaction has been submitted may be different results for the same data read in the same transaction. ③ phantom read, a transaction when reading data, when another transaction inserts some new data in a table reading table again will be more than a few lines, like hallucinations.

Q13: ACID properties brief affairs

A: ①Atomicity represent all operations atomicity, a transaction is indivisible atomic unit, either all succeed, or all fail. ②Consistency indicates that consistency, regardless of the implementation of normal or abnormal exit, the integrity of transactions executed before and after data must be consistent, the total amount of both before and after such transfer is constant. ③Isolation represents isolation, the concurrent operation of different transactions are isolated from each other, they do not affect each other between. ④Durability represents persistence, after the transaction is completed the operation of modified data will be persisted to permanent storage.

Q14: The basic principle outlined in the master copy from

A: ① master, the master data server automatically copied from the copy refers to a database server acting as the master server, one or more additional servers to act as a server from the database from the server. For multi-level replication, the database server can act as a host can also act as a slave. ②MySQL main base is replicated from the primary server to modify the binary database records, from the server through the master binary log automatically perform the update.

Q15: MySQL What lock?

A: ① pressing operation type can be divided into a read lock (shared locks S) and a write lock (exclusive lock X). Read lock: for the same data, multiple read operations can be carried out without affecting each other at the same time. Write lock: until the current operation is not completed, it will block other read and write locks. ② pressing operation is divided into row lock granularity, the lock table, page locks. Line refers to a line data latch lock, an exclusive lock. Table lock refers to locking the whole table of the current operation, simple, low resource consumption. ③ page granularity locking between the lock and the lock table row lock, a lock set of adjacent records.

Q16: What views are? And ordinary table what is the difference?

A: ① view (View) is a virtual presence of the table. View does not actually exist in the database, the table row and column data from the query using the view definition, and is dynamically generated using the view. Popular speaking, the view is the result set of a SELECT statement returns after execution. So when we create a view, the main job creation falls on this SQL query. ② view of advantages relative to conventional table include the following: Simple: the user using the view corresponding to the structure completely without interest behind the table, and conditions associated with filters for filtering the user is already a good condition of the composite the result set. Security: users can only view they are allowed to access the query result set table permissions management and can not be limited to a certain line of a column, but you can view through the simple implementation. Independent Data: structure view Once determined, the table structure can shield the user changes, the source table has no effect on the view columns increases; modified source table column names, can be resolved by modifying the view, will not cause visitors influences.

Q17: What are stored procedures and functions are? What's the difference?

A: ① stored procedures and functions are pre-compiled and stored for a set of SQL statements in the database, call stored procedures and functions can simplify a lot of work application developers to reduce the transmission of data between the database and application server, for improving data processing efficiency is good. ② The difference is that the function must have a return value, the return value is not stored procedure.

Q18: What Triggers are?

A: ① trigger is associated with a table of database objects, refer to before insert / update / delete or after the trigger and the trigger execute SQL statements defined in the collection. This feature can facilitate the application of the trigger end of the database to ensure data integrity, logging, data verification operation. ② use aliases OLD and NEW references to record changes in the content of the flip-flop, which is similar to the other database. Now triggers also only supports row-level trigger, does not support the statement-level trigger.

Q19: understand the architecture of MySQL do?

A: ① link layer: the top is the number of clients and link services, including communications and most local sock-based client / server tools to achieve similar TCP / IP communications. Mainly to complete some similar connection processing, authorization and authentication, and related security solutions. Introduced the concept of the thread pool on the layer, threads provide secure access authentication by the client. Also on this level can be achieved based SSL-secure link. The server also verify it has the operating authority for each client security access. ② service layer: second-tier architecture mainly to complete the majority of core services, such as SQL interface, and complete the cached query, SQL analysis and optimization, the operative part of the built-in functions. All functions across storage engines also achieve this level, such as procedures, functions, and so on. In this layer, the server parses the query and creates internal parse tree, and its corresponding complete optimization table such as the query sequence to determine whether the use of the index, and finally generate the corresponding operation is performed. If the select statement, the server will query cache inside, if the cache space is large enough so that in the settlement of a large number of read operations can be a good environment to enhance the performance of the system. Layer ③ Engine: Engine storage layer, the storage engine really responsible for storage and retrieval of data MySQL, and the server communicate via the API storage engine. Different storage engines have different functions, so that we can according to their need to select the appropriate storage engine. ④ storage layer: data storage layer, mainly on the file system interaction and complete data storage and storage engine.

Q20: How should the storage engine to choose?

A: ① in the choice of storage engine, should choose the right storage engine based on the characteristics of the application system. For complex applications, you may also select various combinations of storage engine according to the actual situation. Here are a few commonly used storage engine environment. ②InnoDB: Mysql is the default storage engine for transaction processing applications, support for foreign keys. If the application integrity of the transaction have higher requirements, data requirements under concurrent conditions consistency, data insertion and query operations in addition to accidents, also includes many updates, deletes, then the InnoDB storage engine is a more appropriate choice. InnoDB storage engine in addition to effectively reduce due delete and update locks cause, but also to ensure that the most appropriate complete and submit the transaction is rolled back, for similar billing system or financial system for data accuracy requirements are relatively high system, InnoDB is s Choice. ③MyISAM: If the application is read and insert operations-based, only a few of update and delete operations, and the integrity of the transaction, concurrency requirements are not high, then choose the storage engine is very appropriate. ④MEMORY: all data stored in RAM, in the need to quickly locate records and other similar data environment that provides access to a few. MEMORY flaw is that there are restrictions on the size of the table, the table can not be much of a cached in memory, followed by the table to ensure that the data can be restored, the data in the table after abnormal termination of the database can be restored. MEMORY tables are usually updated less frequently for a small table to quickly get access to the results. ⑤MERGE: for a series of identical MyISAM tables together in a logical manner, and as an object reference them. MERGE advantage is that the table can break the limit for a single MyISAM tables, and the different tables by distributed across multiple disks, can effectively improve access efficiency MERGE table. It is very suitable for storage, such as data warehousing and other VLDB environments.

Q21: SQL optimization step to understand it?

A:
① view the SQL execution frequency.
② positioning inefficient implementation of SQL. Through the following two ways: Slow query log: locate those lower efficiency in the implementation of SQL statements by the slow query log. show processlist: Slow query log was recorded after the end of the query, so when there is a problem in the application reflect the efficiency of the query and slow query log can not locate the problem, you can use the show processlist command to view the current thread MySQL in progress, including the state of the thread, whether lock tables, etc., can be viewed in real-time implementation of SQL, as well as some table lock to optimize the operation.
③ After the query to inefficient SQL statements above step, can obtain information about how MySQL performs a SELECT statement, including the order of how to connect and connection table during execution by EXPLAIN SELECT statement or command DESC.
④Mysql from version 5.0.37 adds support for beginning and show profiles show profile statements. show profiles can help us in doing SQL optimization takes time to understand where we are. ⑤MySQL5.6 provides tracking trace of SQL through trace files can learn more about why the optimizer choose Plan A, Plan B rather than choose. Open trace, set the format to JSON, and set the maximum trace memory size that can be used to avoid default resolution process because the memory is too small and not able to complete the show.

end: If you think this article helpful to you, remember to focus praise forwarding, update your support is my motivation.

Guess you like

Origin blog.51cto.com/14409100/2484808