Compare database

MySQL

1. Four characteristics Affairs

Atomicity: indivisible operation unit, all operations in the transaction, either all succeed; or withdrawn into the state before the transaction execution
Consistency: Before executing the transaction if the database is consistent, then after the execution of the transaction database is still the same;
Isolation: between independent and transparent independent from other transaction operations. Affairs independently. This is usually achieved using a lock. The result of a transaction, affects other transactions, other transactions will be withdrawn. 100% of the transaction's isolation, the need to sacrifice speed.
Durability: Once a transaction is committed, the result is permanent. Even if a system failure occurs, it can be restored.

 

2.MySQL transaction isolation level

Uncommitted Read (Read Uncommitted): dirty reads are allowed, as long as the other modified transaction data, even uncommitted, this transaction data can also see the modified value. That is probably not read other sessions modify the transaction data submitted
Read Committed (Read Committed): you can only read the data already submitted. Most Oracle and other database is the default level (not repeatable read).
Repeatable Read (Repeated Read): Read repeatable. Whether or not modified, and other matters submitted data, see the value in that transaction data are not always affect other matters.
Serial Read (Serializable): fully serialized read, each reading will need to obtain a shared table-level locking, read and write will block each other
MySQL Database (InnoDB engine) is used by default Repeatable read (Repeatable read)

 

3. What is the index, what are the four categories index

Database indexing, database management system, a sort of data structure to assist in rapid query, update data in a database table. Achieve an index commonly used B_TREE. B_TREE indexes to speed up data access, because the storage engine does not go scan the entire table to get the data you need; rather, it starting from the root, root pointer to save the child node, the storage engine will quickly find the data according to the pointer.
index ---- ordinary index, the data can be repeated without any restrictions. 
UNIQUE ---- unique index, the column value of the index required to be unique, but allow free value; if the index is a combination, the combination of the column values must be unique.
primary key ---- the primary key index, is a special unique index, a table can have only one primary key, does not allow null values, generally create a primary key index while creating the table.
---- index composite index created on multiple fields, only use the first field when creating an index in a query, the index will be used.
fulltext ---- full-text indexing, text fields for a large table: char, varchar, text columns to create a full-text index is mainly used to find text keyword is not directly comparable with the value of the index. fulltext more like a search engine, with the match against operational use, rather than a general statement where plus like.
Note: The full-text index is currently only MyISAM storage engine supports full-text index, InnoDB engine version 5.6 does not support the full-text index

4. Database three paradigms

The first paradigm: 1NF atomic constraints on properties required field is atomic, no longer decomposition; (as long as it satisfies the relational database 1NF)
The second paradigm: 2NF is the premise of meeting the first paradigm of non-primary key field can not be partially dependent on the primary key appear; solve: the elimination of the composite primary key can be avoided since section, increase single keyword appears.
The third paradigm: 3NF is the premise of meeting the second paradigm, the non-primary key field dependent transfer can not occur, such as a field depend on a primary key, and a number of fields dependent field, which is dependent transmission. Solution: a data entity information in a table in the realization.

The difference between the storage engine MyISAM and InnoDB

1) InnoDB support transactions, MyISAM does not support.
2) MyISAM for query-based applications as well as insert, InnoDB for frequent modifications, and involve high security applications.
3) InnoDB support foreign keys, MyISAM does not support.
4) From MySQL5.5.5, InnoDB is the default engine.
5) MyISAM supports full-text indexing type, while InnoDB does not support full-text indexing.
6) total number of rows is not saved in the InnoDB table, select count (*) when from table, InnoDB needs to scan the entire table to calculate how many rows, but MyISAM simply read out the saved total number of rows can be. Note: When the count (*) statement contains a condition where MyISAM also need to scan the entire table.
7) For the field of self-growth, InnoDB must contain only the index of the field, but in the MyISAM table can index and other fields to establish a joint together.
8) Empty the entire table, InnoDB is to delete the line by line, the efficiency is very slow. MyISAM will rebuild the table. MyisAM use the delete statement immediately after the deletion does not clean up disk space, need regular cleaning, the command: OPTIMIZE table dept;
9) InnoDB row lock support (in some cases the whole table is locked as update table set a = 1 where user like '% lee%')
10) Myisam create table generating three files: .frm structure of the table, data files .MYD, .MYI index file, only generate a Innodb .frm file, data stored in the ibdata1.log
Now generally use InnoDB, MyISAM mostly full table lock, read and write serial problem, complicated by the efficiency of the lock table, inefficient, MyISAM for read-intensive applications do not normally go chosen.

The difference 6.CHAR and VARCHAR

CHAR and VARCHAR types differ in terms of storage and retrieval
CHAR column length is fixed length when creating the specified table, a length range from 1 to 255
When CHAR values ​​are stored, they are padded with spaces to a certain length, trailing spaces to be deleted CHAR values ​​are retrieved.

What kinds of locks in 7.Mysql

MyISAM supports table locks, InnoDB support table and row locks, row locks by default
Table-level lock: Small overhead, locking fast, will not deadlock. Lock intensity, the highest probability of lock conflicts, concurrent minimum amount
Row-level locking: large overhead, locking slow, there will be a deadlock. Lock efforts, small probability of lock conflicts, the maximum concurrency

8. Description of the connection, left outer, right outer connection inquiry procedure

En: Remove the table from left to each record, all the records are matched with the right table, it must be a condition, the same as [in] the public portion of the left and right tables, the result will be retained or not retained.
Left outer join: (whether there is a line to match them regardless of the table on the right) contains all the rows of the left table and the right table of all matching rows.
Right external connection: the right side of the table contains all of the rows (regardless of whether there is a row in the left table to match them), and the left of the line table match all.

Question 9.SQL statement

 

 

 

MongoDB

1. What is MongoDB

MongoDB is a document database that provides good performance, leading non-relational database. BSON using stored document data.
The BSON () is a binary form of a class json storage format, referred to as Binary JSON. Json more with respect to the date type and binary array.

2. What is the set (table)

MongoDB collection is a set of documents. It is equivalent to a relational database table concept (RDBMS) in. A collection in a separate database. 
Multiple documents within a collection can have a number of different fields. In general, the collection of documents have the same or related purposes.

3. What is the document (Record)

Documentation consists of a set of key value components. Document is a dynamic mode, which means that the same set of documents in the field and does not need to have the same structure. In a relational database, each record in the table is equivalent to a document in MongoDB.

4.MongoDB support primary key foreign key relationship it

The default MongoDB does not support the primary key and foreign key relationships. Mongodb itself needs hard coded API can be achieved with a foreign key, unintuitive and difficult to
large

5. How to perform transactions / locking

mongodb not use the traditional locks or complex transactions with rollback, as it aims to design a lightweight, fast and predictable performance. It can be likened to mysql mylsam automatic commit mode by streamlining support for transactions , performance has improved, particularly in a system more likely to pass through the server's.

Redis

1. What is the Redis persistence? Redis, which has several persistent way?

Persistence is the memory of the data written to disk to prevent service downtime memory data loss.
Redis persistence provides two ways: RDB (default) and AOF 

Which architectural patterns 2.Redis there? Talk about their characteristics

single vision
     Features: Simple
     Question: 1 limited memory capacity is limited 2. 3. processing power can not be highly available.
Master-slave replication
     Redis replication (Replication) function allows the user to create any number of copies of the server based on a Redis server, wherein the server is a master is copied (Master), and by copying replicas was created out of the server from the server ( slave). As long as the primary connection between the network server from normal, from both the master server will have the same data, the main server will have to happen to them to synchronize data updates from the server, which has been the main guarantee of the same data from the server.
     Features: 1, master / slave roles 2, the same 3 master / slave data, reducing the pressure reading transmitted from the master library
     Question: 2. 1 can not guarantee availability does not solve the master wrote pressure
sentinel
     Redis sentinel a distributed system is monitored from redis master server, and automatically failover the primary server offline. Three characteristics: 1 monitoring (Monitoring):. Sentinel will continue to check whether your home server and from the server functioning properly. 2. Reminds (Notification): When monitoring a Redis server problem, Sentinel can send notifications to the administrator or other applications via the API. 3. Automatic failover (Automatic failover): when a primary server is not working properly, Sentinel will automatically start a failover operation.
     Features: 1, to ensure high availability 2, each node monitor 3, automatic failover
     Disadvantages: 1. master-slave mode, switching takes time to lose the data written 2. master pressure does not solve the
Cluster (proxy type)
     Twemproxy is an open source Twitter memcache and redis a quick / lightweight proxy server; Twemproxy is a fast single-threaded proxy program, supported Memcached ASCII protocol and redis agreement.
     Features: 1, more hash algorithm: MD5, CRC16, CRC32, CRC32a, hsieh, murmur, Jenkins 2, 3 support a failed node is automatically deleted, the rear end of the business logic slice Sharding transparent, read and write operations and operation of a single party Redis agreement
     Disadvantages: 1 added a new proxy, needs to maintain its high availability. 2.failover need to implement the logic itself can not support automatic transfer failure poor scalability, capacity for scaling requires manual intervention
Cluster (direct type)
     From then redis 3.0 Supported redis-cluster clustering, Redis-Cluster-free central structure, each of the data storage node and the entire state of the cluster, every node and all other nodes are connected.
     Features: 1, no center architecture (which affect the performance bottleneck node does not exist), less a proxy layer. 2, according to the data slot is stored in a plurality of distributed nodes, inter-node data sharing, data distribution can be dynamically adjusted. 3, scalability, linearly expandable to 1000 nodes, the nodes may be dynamically added or deleted. 4, high availability, the partial node is not available, the cluster is still available. Make a backup copy of the data by increasing the Slave 5, between failure to achieve automatic failover, nodes exchange status information through gossip protocol to complete the Master Slave to enhance the role by voting mechanism.
     Disadvantages: 1, resource isolation is poor, the situation is prone to influence each other. 2, asynchronous data replication, does not guarantee strong data consistency
3. Used Redis distributed lock it, it is how to achieve?
Setnx scramble to acquire a lock, then grabbed, and then add a lock to expire expiration prevent lock forget released.
4. Redis used to do asynchronous queue it, how do you use? What are the disadvantages?
Structure is generally used as a queue list, rpush message production, lpop consumption message. Lpop when no message to a proper sleep will try again.
Cons: In the case of the consumer off the assembly line, production will be lost messages, message queues have to use professional as rabbitmq and so on.

5. What is the cache penetrate? How to avoid? What is Cache avalanche? Ru avoid?

Cache penetration
General caching system, it is in accordance with the key to cache query, if the corresponding value does not exist, they should go to find the back-end systems (such as DB). Some deliberately malicious request query key is not present, a large amount of the request, it will cause a lot of pressure on the back-end systems. This is called caching penetration.
How to avoid
1: the case where an empty result set also caching and set shorter, or the data key corresponding to the dirty cache after the insert.
2: is not present on certain key filtered. We can put all the possible key into a large Bitmap by the bitmap filter query.
Cache avalanche
When the cache server reboot or a large number of cache concentrated in one time period fail, so that when failure, back-end systems will bring a lot of pressure. Cause the system to crash.
How to avoid
1: After a cache miss, by locking to control the number of threads or queue database read write cache. For example, a key for allowing only one thread to query the data and write cache, other threads wait.
2: Make secondary cache, cache the original A1, A2 copy is cached, when A1 fails, access to A2, A1 cache expiration time is set short-term, A2 is set for long-term
3: a different key, to set different expiry time for the point in time of a cache miss as even as possible.
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/ln-xx/p/12100170.html