Java interview questions - easy to understand mysql related questions

insert image description here
1. The difference between MYSQL storage engine MYISAM and InnoDB

1. MYISAM requires less storage space; InnoDB requires more memory and storage space.

2. MYISAM does not support transactions; InnoDB supports transactions.

3. MYISAM is faster in the select query, and has a counter inside, which can be called directly; InnoDB does not.

4. MYISAM supports table-level locking; InnoDB not only supports table-level locking, but also supports row-level locking, so it also supports high concurrency.

2. What is an index and why should it be built?

The index is like the catalog in the book, through which the specific content in the data can be searched, and it exists as a pointer in the data table;

The advantage is to speed up the retrieval and improve the system performance. The disadvantage is that the index needs to occupy the physical space of the disk and maintain the table. When adding, modifying, and deleting operations in the table, the index needs to be dynamically maintained, so the execution efficiency will be reduced.

3. What types of MYSQL indexes are there?

Primary key index: Each table has only one primary key index, indicating that data columns cannot be repeated.

Unique index: data columns are not allowed to have duplicates, but can be NULL values.

Ordinary index: It is an ordinary index without any restrictions.

Full-text index: It is mainly used to find keywords in the text, which is equivalent to a search engine.

Fourth, the principle of indexing, the principle of creating an index

It is to turn unordered records into ordered query results.

in principle:

1. Frequently updated fields are not suitable for indexing

2. Frequent operations on query fields are suitable for indexing

3. Combined index, according to the left query matching principle

4. Columns with foreign keys must be indexed

5. For the fields text and image, which involve a lot of content, they are not suitable for indexing

5. What are the four characteristics of database transactions

1. Atomicity: The smallest unit of transaction execution, which means that the execution is either completely completed or not completed.

2. Consistency: After the transaction is executed, the data remains consistent.

3. Isolation: Under the concurrent execution of data, the access between transactions exists independently.

4. Persistence: After the transaction is committed, the data changes are persistent and will not change due to external factors, such as power failure, database failure, etc.

6. What is dirty reading and phantom reading

Dirty read: A transaction has been updated, but the read data is still the previous data.

Phantom read: After a transaction executes a query operation, inconsistent data appears before and after the query.

7. What are row-level locks, table-level locks, and page-level locks?

Row-level lock: It is the lock with the finest lock grain level, but the cost of locking is the largest, and it locks the rows in the table.

Table-level lock: It is the lock with the largest lock grain level. It locks the entire table, which is easy to implement and consumes less resources.

Page-level lock: It is a lock between row-level locks and table-level locks, and is used to lock a group of adjacent records.

8. What are the types of MySQL locks?

Shared lock: Also known as a read lock, a shared lock is added at the same time when the user performs data read operations.

Exclusive lock: also known as write lock, when a user writes data, an exclusive lock is added at this time, and other users are not allowed to operate again.

Nine, how to solve the database deadlock

Deadlock is a deadlock phenomenon in which two or more transactions rob resources and request each other to lock resources, resulting in a vicious circle.

Solution:

1. In the same transaction, try to lock all required resources at once to reduce the probability of deadlock.

2. Upgrade the lock level, from the previous table-level lock or page-level lock to row-level lock.

3. If there are many businesses, you can use distributed transaction locks or optimistic locks

10. What are optimistic locks and pessimistic locks?

Optimistic locking: Under concurrent conditions, data locking is performed by setting the version number in the database.

Pessimistic locking: Under concurrent conditions, use the locking mechanism of the database to shield operations that may violate data integrity.

Report/Feedback
Post a comment
Post a comment
Post
the author's latest article

The meaning of circles, disadvantaged groups, and the destination of life2022-01-12
21
reading

How to feel truly in love with
someone2022-01-10
68Read

The Solution to Study Weariness and Mediocrity—Ostrich Thinking and Cask Theory2022-01-08
115
Reading
Related Recommendations


Tencent cloud database MySQL uses Intel oneAPI to achieve significant performance improvement up to 85%

Use the datax tool to synchronize the full amount of MongoDB data to mysql
Develop Paper

How to apply to develop a WeChat Mini Program? What conditions are required?
App Park app development company

Java System Learning Framework
Programmer Fan Mouxin

Springboot integrates MongoDB to realize the function of data modification, deletion and pagination
Little Treasure Reader
1 Guiyang screened 301 cases of positive infection Hot 2 Luding
earthquake killed 74 people and 35 lost contact Hot 3 China's economy embarked on a new journey of modernization 4 After 00, the boss deducted 50% of the employee's salary during the Mid-Autumn Festival to show filial piety 5 The Indian baby boy was taken away and the mother opened the tiger's mouth to save the child 6 The girl was arrested for drunk driving and said she just kissed a drinker 7 The owner of a pawn shop in the United States was threatened with death 8 iPhone14 Summary of exposed information 9 Medical experts in Luding, Sichuan: The situation is more serious than imagined


















Guess you like

Origin blog.csdn.net/m0_54861649/article/details/126753671