Ali is cool on three sides! I was stunned by the basics and source code of MySQL, and won the Jingdong offer

As a back-end developer, MySQL is one of the most commonly used relational databases at work. With the rapid development of the mobile Internet, the cluster architecture has become a mainstream trend, and the requirements for high concurrency and high availability of the database are becoming higher and higher.

Whether the applicant has the ability to control the underlying mechanisms and principles has become an important assessment criterion for Internet companies to screen talents. If you only stay at the basic operation level of building a database, creating a table, adding, deleting, and checking, you will sooner or later be eliminated by the enterprise.

Give three chestnuts (frequently asked by interviewers):

  • How to improve query performance?
  • How to break through the performance bottleneck of a single library?
  • How to achieve high concurrency and high availability of the database?

Below, in order to prevent you from stumbling on questions, I have compiled a PDF document for common MySQL interviews for everyone to check and fill vacancies.

  • Document features: clear organization, combination of graphics and text, easy to understand
  • In order to have a better reading experience for everyone, only part of the content of each knowledge point is shown here, if you need to study the content of this document systematically

1. Basic knowledge of database

1. Why use a database

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

2. What is SQL?

Structured Query Language (Structured Query Language) referred to as SQL, is a database query language.

Role: used to access data, query, update and manage relational database systems.

3. What is MySQL?

MySQL is a relational database management system, developed by the Swedish company MySQL AB, under the umbrella of Oracle

product. MySQL is one of the most popular relational database management systems. In terms of web applications, MySQL is the most popular

Good RDBMS (Relational Database Management System, relational database management system) application

One of the software. It is very commonly used in Java enterprise-level development, because MySQL is open source, free, and easy to extend.

4、........

Two, data type

1. What data types does mysql have

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

3. Engine

1. The difference between MySQL storage engine MyISAM and InnoDB

Storage engine: How the data, indexes and other objects in MySQL are stored, is a set

Implementation of the file system.

The commonly used storage engines are as follows:

Innodb engine: Innodb engine provides support for database ACID transactions. And also provides row-level lock

And foreign key constraints. The goal of its design is to handle a database system with large data capacity.

MyIASM engine: (originally the default engine of Mysql): does not provide transaction support, nor does it support row-level locks and foreign keys.

MEMORY engine: All the data is in the memory, the data processing speed is fast, but the security is not high.

2. The difference between MyISAM and InnoDB

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

3. Four major features of InnoDB engine

  • Insert buffer
  • Double write
  • Adaptive hash index (ahi)
  • 预读(read ahead)

4. Storage engine selection

If there is no special requirement, just use the default Innodb.

MyISAM: Applications that focus on reading and writing, such as blog systems and news portals.

Innodb: update (delete) operation frequency is also high, or to ensure the integrity of the data; high concurrency, support for transactions and

Foreign key. Such as OA automated office system.

Four, index

1. What is an index?

2. What are the advantages and disadvantages of indexes?

3. Index usage scenarios (emphasis)

4. What are the types of indexes?

5. Index data structure (b tree, hash)

6. Basic principles of indexing

7. What are the indexing algorithms?

8. The principle of index design?

9, the principle of creating an index (the top priority)

10. Three ways to create an index, delete an index

11. What should I pay attention to when creating an index?

12. Can index query definitely improve query performance? why?

13. How to delete millions of data or more

14. Prefix index

15. What is the leftmost prefix principle? What is the leftmost matching principle

16. The difference between B tree and B+ tree

17. The benefits of using B-trees

18. The benefits of using B+ trees

19.What is the difference or pros and cons between Hash index and B+ tree?

20. Why does the database use B+ trees instead of B trees?

21. The B+ tree does not need to go back to the table to query data when it meets the clustered index and the covering index

22. What is a clustered index? When to use clustered index and non-clustered index?

23. What is a joint index? Why do we need to pay attention to the order in the joint index?

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

Five, affairs

1. What is a database transaction?

2. What are the four characteristics of things (ACID)?

3. What is dirty reading? Phantom reading? Not repeatable?

4. What is the isolation level of a transaction? What is the default isolation level of MySQL?

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

Six, lock

1. Do you understand MySQL locks?

When the database has concurrent transactions, data inconsistencies may occur. At this time, some mechanism is needed to ensure the order of access. The lock mechanism is such a mechanism.

Just like a hotel room, if everyone enters and exits at will, there will be multiple people robbing the same room, and a lock is installed on the room, and the person who applies for the key can check in and lock the room. Others only wait for him to use it. It can be used again.

2. The relationship between isolation level and lock

3. What are the database locks according to the lock granularity? Locking mechanism and InnoDB lock algorithm

4. What is a deadlock? How to deal with it?

Deadlock refers to the phenomenon that two or more transactions occupy each other on the same resource and request to lock each other's resources, which leads to a vicious circle.

Common methods to solve deadlock:

1. If different programs will access multiple tables concurrently, try to agree to access the tables in the same order, which can greatly reduce the deadlock

meeting.

2. In the same transaction, try to lock all the resources needed at once to reduce the probability of deadlock;

3. For business parts that are very prone to deadlock, you can try to upgrade the lock granularity, and reduce it through table-level locking.

Less probability of deadlock;

If the business is not handled well, you can use distributed transaction locks or use optimistic locks

5、.......

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

Seven, view

1. Why use views? What is a view?

In order to improve the reusability of complex SQL statements and the security of table operations, the MySQL database management system provides views

characteristic. The so-called view is essentially a virtual table, which does not exist physically. Its content is similar to the real table.

Contains a series of named column and row data. However, the view does not exist in the database as stored data values. Row

And column data comes from the basic table referenced by the query of the defined view, and is dynamically generated when the view is specifically referenced.

The view allows developers to only care about certain specific data and specific tasks they are responsible for, and can only see what is defined in the view

Data, rather than the data in the table referenced by the view, thereby improving the security of the data in the database.

2. What are the characteristics of the view?

  • The columns of the view can come from different tables, which are abstractions of tables and new relationships established in a logical sense.
  • A view is a table (virtual table) generated from a basic table (real table).
  • The creation and deletion of views does not affect the basic table.
  • Updates (addition, deletion and modification) to the view content directly affect the basic table.
  • When the view comes from multiple basic tables, adding and deleting data is not allowed.

View operations include creating views, viewing views, deleting views and modifying views.

3. What are the usage scenarios of the view?

The basic purpose of the view: simplify sql query and improve development efficiency. If there is another use, it is to be compatible with old watches

structure.

The following are common usage scenarios for views:

  • Reuse SQL statements;
  • Simplify complex SQL operations. After writing a query, you can easily reuse it without knowing its basic query details;
  • Use part of the table instead of the entire table;
  • Protect data. Users can be granted access to a specific part of the table instead of access to the entire table;
  • Change the data format and presentation. The view can return data that is different from the representation and format of the underlying table.

4、.....

Eight, stored procedures and functions

1. What is a stored procedure? What are the advantages and disadvantages?

A stored procedure is a pre-compiled SQL statement. The advantage is that it allows a modular design, that is, it only needs to be created once.

It can be called multiple times in the program later. If a certain operation needs to execute SQL multiple times, using stored procedures is more than pure

SQL statement execution must be fast.

advantage:

1) The stored procedure is pre-compiled and the execution efficiency is high.

2) The code of the stored procedure is directly stored in the database, and the stored procedure name is directly called to reduce network communication.

3) High security, users with certain permissions are required to execute stored procedures.

4) Stored procedures can be reused, reducing the workload of database developers.

Disadvantages:

1) Debugging is troublesome, but debugging with PL/SQL Developer is very convenient! Make up for this shortcoming.

2) The problem of porting, the database-side code is of course related to the database. But if it is an engineering project, there is basically no

In the transplant problem.

3) Recompilation problem, because the back-end code is compiled before running, if the object with the reference relationship changes,

The affected stored procedures and packages will need to be recompiled (but it can also be set to automatically compile at runtime).

4) If a large number of stored procedures are used in a program system, when the program is delivered to use, with the increase of user demand

The addition will lead to changes in the data structure, and then the related problems of the system. Finally, if the user wants to maintain the system, it can be said

It is very difficult, and the price is unprecedented, and it is more troublesome to maintain.

In fact, there are more knowledge about the database and interview questions. Due to space limitations, to avoid affecting the reading experience, the following content is shared in the form of screenshots.

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

Ali is cool on three sides!  I was stunned by the basics and source code of MySQL, and won the Jingdong offer

 

 

Guess you like

Origin blog.csdn.net/Sqdmn/article/details/108586970