Java the most common interview questions: Module seventeen

Seventeen, MySql

 

What three paradigms 164. The database is?

  • The first paradigm: emphasized that the atomic columns, each column is indivisible i.e. atomic data items in the database table.

  • The second paradigm: the entity attribute requirements entirely dependent on the primary key. The so-called completely dependent refers not only depend on the presence of the main part of the key attributes.

  • Third Pattern: Any non-primary property is not dependent on other non-primary property.

165. increment table inside a total of seven data, delete the last two data, restart the mysql database, and insert a piece of data, this time id is a few?

  • If the table type is MyISAM, that id is 18.

  • If the table type is InnoDB, that id is 15.

 

InnoDB tables will only increment primary key id of the largest recorded in the memory, so after the restart will result in the greatest loss of id.

166. How to get the current version of the database?

Use select version () to get the current version of the MySQL database.

167. What ACID talk about that?

  • Atomicity (Atomicity): all operations a transaction (transaction) in, or completed, or not completed all, does not end in the middle of a link. Transaction error occurs during execution, it will be restored (Rollback) to the state before the start of the transaction, as the transaction never performed the same. That is, the transaction indivisible, irreducible.

  • Consistency (Consistency): and after the end of the transaction before the transaction began, the integrity of the database is not corrupted. This means that data written must be fully compliant with all the default constraints, triggers, and other cascading rollback.

  • Isolation (isolation): a plurality of concurrent transactions database allows simultaneous read and write capabilities and modify its data, the isolation can be prevented when a plurality of transactions concurrently perform cross executed result in inconsistent data. Transaction isolation divided into different levels, including Uncommitted Read (Read uncommitted), Read Committed (read committed), repeatable read (repeatable read) and serialized (Serializable).

  • Durability (persistence): After the transaction, to modify the data is permanent, even if the system failure will not be lost.

What is the difference 168. char and varchar is?

char (n): fixed-length type, such as subscription (10), when you enter "abc" three characters, which accounts for 10 bytes of space or char, the other seven are null bytes.

chat advantages: high efficiency; disadvantages: space; application scenarios: MD5 value storing passwords, fixed length, very suitable for use char.

varchar (n): a variable length, the value is stored together with the value of each byte is used to record occupies a byte length of its length.

Therefore, from the appropriate space considerations varcahr; char considered suitable from the efficiency, the use of both the trade-off.

What is the difference 169. float and double that?

  • float can store up to eight decimal digits, and occupies 4 bytes in memory.

  • Most double store 16 may be a decimal number, and 8 bytes in memory.

En 170. mysql, the left join, right join what is the difference?

En keywords: inner join; connect the left: left join; the right connection: right join.

 

The connection is associated with the matching data shown; the left is connected to all displayed table on the left, the right table shows the qualified data; right connecting opposite.

171. mysql index is how to achieve?

The index is a data structure to meet a particular search algorithm, and these data structures in some way to the data, in order to achieve efficient to find data.

 

Specifically, after MySQL on the index, different data engine to achieve different, but the current mainstream database engine B + tree index is implemented, search efficiency B + tree can reach performance dichotomy, locate the data area We found a complete data structure, and performance of all indexes is better.

172. The index mysql how to verify whether to meet the demand?

View explain how to use SQL query is executed, the index is to analyze your needs.

 

explain 语法:explain select * from table where type=1。

173. say about the transaction isolation database?

MySQL transaction isolation was added in MySQL ini configuration file, and finally add in the file:. Transaction-isolation = REPEATABLE-READ

 

Available configuration values: READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE.

 

  • READ-UNCOMMITTED: read uncommitted, the lowest isolation level, before the uncommitted transactions, it can be read by other transactions (Magic will read, dirty reads, non-repeatable read).

  • READ-COMMITTED: read committed, after a transaction commits to be read by other transactions to (cause phantom reads, non-repeatable read).

  • REPEATABLE-READ: When a repeatable read, the default level, reading the same data multiple times to ensure that the value of content and transaction start time is the same, read to prohibit other data uncommitted transactions (cause phantom read) .

  • SERIALIZABLE: serialization, the costliest most reliable isolation level, the isolation level can prevent dirty reads, non-repeatable read, phantom read.

 

Dirty read: that a transaction can read data another transaction has not been committed. For example, attempts to insert a transaction record A, at which point the transaction has not been submitted, and then attempts to read the other transaction records to A.

 

Non-repeatable read: refers to a transaction, reading the same data multiple times.

 

Magic Reading: refers several times within the same transaction query returns a result set is not the same. For example, the same transaction A first query when there are n records, but the second inquiry under the same conditions, there are n + 1 records, which seems to hallucinate. Magic Reading occurs because another transaction also add or delete or modify the result set inside the first transaction data, data content the same record is modified, all recorded data lines becomes more than or fewer.

174. mysql talk about common engine?

InnoDB engine: InnoDB database engine provides support for acid affairs, and also provides a constraint row-level locking, and foreign keys, its design goal is to handle large data capacity database system. When running MySQL, InnoDB buffer pool will be created in memory for buffering data and indexes. But the engine does not support full-text search, but also relatively slow start, it is the number of rows in the table will not be saved, so when performing select count (*) from table command when the need for a full table scan. Due to the small size of the lock, the lock will not write a full table, so use will increase efficiency at higher degree of concurrency scene.

 

MyIASM engines: MySQL default engine, but does not provide support for transactions, row-level locking and does not support foreign keys. Therefore, when performing insert and update statements that write operation is performed when the need to lock the table, it will result in efficiency will be reduced. But the difference is, and InnoDB, MyIASM engine is to preserve the number of rows in the table, so when performing select count (*) from table when the statement can be directly read the saved values ​​without the need to scan the entire table. So, if the table read much more than write operations, and does not require support of transactions can be MyIASM as the preferred database engine.

175. talk about mysql row locks and table locks?

MyISAM only supports table locks, InnoDB support table and row locks, row locks by default.

 

  • Table-level lock: Small overhead, locking fast, will not deadlock. Lock large particle size, the highest probability of lock conflicts, the minimum amount of concurrency.

  • Row-level locking: large overhead, locking slow, there will be a deadlock. Lock efforts, small probability of lock conflicts, the highest degree of concurrency.

176. say something optimistic and pessimistic locking?

  • Optimistic locking: every time that others pick up data are not modified, so it will not be locked, but when submitted updated during this time will determine what others do not have to update the data.

  • Pessimistic locking: every time someone else to pick up data are considered to be modified, so every time she took the data will be locked, so people want to take this data will be blocked until the lock is released.

 

Optimistic locking of the database need to implement, add a version field in the table inside, each modification success value plus 1, so each modification when the first compare, if you have a version of the database and the current version, and if not do not modify, so to achieve optimistic locking.

177. mysql troubleshooting Which means there?

  • Use the command to view the current show processlist all connection information.

  • Use explain command to query SQL statement execution plans.

  • Turn on slow query log for slow SQL queries.

178. How do performance optimization of mysql?

  • Create an index for the search field.

  • Avoid using select *, lists the fields to be queried.

  • Vertical division part table.

  • Choosing the right storage engine.

 

(Finish)

Guess you like

Origin www.cnblogs.com/xiaofengwang/p/11258892.html