当前位置:网站首页>MySQL kills 10 people. How many questions can you hold on to?

MySQL kills 10 people. How many questions can you hold on to?

2022-06-24 22:57:00 Gemcoder

MySQL I'm often asked in an interview , This article summarizes the classic questions in the interview .

1. What are the three paradigms of database ?

First normal form : No more columns can be split .

Second normal form : On the basis of the first paradigm , Non primary key columns are completely dependent on the primary key , Instead of relying on a part of the primary key .

Third normal form : On the basis of the second paradigm , Non primary key columns only depend on the primary key , Not dependent on other non primary keys .

When designing the database structure , Try to follow the three paradigms , If not , There must be a good reason .

Such as performance . In fact, we often compromise database design for performance .

2.mysql What are the tables about permissions ?

MySQL The server controls the user's access to the database through the permission table , The authority list is stored in mysql In the database , from mysql_install_db Script initialization .

These permission tables are user,db,table_priv,columns_priv and host.

user Permissions on the table : Record the user account information allowed to connect to the server , The permissions in it are global .

db Permissions on the table : Record the operation authority of each account on each database .

table_priv Permissions on the table : Record data table level operation authority .

columns_priv Permissions on the table : Record the operation authority of data column level .

host Permissions on the table : coordination db The permission table provides more detailed control over the database level operation permissions on a given host . This permission table is not subject to GRANT and REVOKE Statement impact .

3.SQL What are the main types of sentences ?

· Data definition language DDL(Data Ddefinition Language)CREATE,DROP,ALTER

Mainly for the above operations , That is to say, it has operation on logical structure , This includes table structure , Views and indexes .

· Data query language DQL(Data Query Language)SELECT

This is easier to understand , That is, query operation , With select keyword .

Various simple queries , The connection query belongs to DQL.

· Data manipulation language DML(Data Manipulation Language)INSERT,UPDATE,DELETE

Mainly for the above operations , That is, to operate on data , Corresponding to the above query operation DQL And DML The common operations of adding, deleting, modifying and checking are constructed by the author . Query is a special kind , Be divided into DQL in .

· Data control function DCL(Data Control Language)GRANT,REVOKE,COMMIT,ROLLBACK

Mainly for the above operations , That is to the database security integrity and other operations , It can be simply understood as permission control, etc .

4. What is a deadlock ? How to solve ?

Deadlock means that two or more transactions occupy each other on the same resource , And ask to lock the other party's resources , Which leads to a vicious circle .

Common solutions to deadlock :

If different programs access multiple tables simultaneously , Try to agree to access tables in the same order , Can greatly reduce the chance of deadlock ;

In the same transaction , Try to lock all the resources you need at once , Reduce the probability of deadlock ;

For business parts that are very prone to deadlock , You can try using upgrade lock granularity , Table level locking is used to reduce the probability of deadlock ;

If business processing is not good, you can use distributed transaction lock or optimistic lock .

5. What is dirty reading ? Fantasy reading ? It can't be read repeatedly ?

Dirty reading (Drity Read): A transaction has updated a data , Another transaction reads the same data at this time , For some reason , Previous RollBack The operation , Then the data read by the latter transaction will be incorrect .

It can't be read repeatedly (Non-repeatable read): Data inconsistency in two queries of a transaction , This may be a transaction inserted between the two queries to update the original data .

Fantasy reading (Phantom Read): In two queries of a transaction , Inconsistent number of data transactions , For example, a transaction queries several columns (Row) data , Another transaction inserts new columns of data at this time , The previous transaction is in the next query , You'll find several columns of data that it didn't have before .

6.SQL Life cycle of ?

① The application server establishes a connection with the database server

② The database process gets the request sql

③ Parse and generate execution plan , perform

④ Read data into memory and do logical processing

⑤ Through step 1 connection , Send results to client

⑥ Turn off the connection , Release resources

7.MySQL database cpu Soar to 100% How to deal with it ?

When cpu Soar to 100% when , Use the operating system command first top Command to observe if mysqld Occupation causes .

If not , Find out which processes are taking up the most , And deal with it .

If it is mysqld Caused by the ,show processlist, Look at what's running inside session situation , Is there a consumption of resources sql Running . Find out what's consuming sql, See if the execution plan is accurate ,index Missing , Or the amount of data is too large .

Generally speaking , Definitely kill Drop these threads ( Observe at the same time cpu Is the usage rate down ), And so on ( For example, index 、 Change sql、 Change memory parameters ) after , Run these again SQL.

It's also possible that it's every sql It doesn't cost much , But all of a sudden , A large number of session The connection leads to cpu soaring , In this case, we need to work with the application to analyze why the number of connections will surge , Then make the corresponding adjustment , For example, limit the number of connections .

8.MySQL What problems does master-slave replication solve ?

The role of master-slave replication is :

There's a problem with the main database , Can switch from database . It can separate reading and writing at the database level . Daily backup can be done from the database .

The data distribution : Start or stop copying at will , And distributed data backup in different geographical locations

Load balancing : Reduce the pressure on a single server

High availability and fail over : Help applications avoid single point of failure

Upgrade test : You can use a higher version of MySQL As a slave Library

9.MySQL What are the common backup tools ?

Common backup tools mysql Copy :

Logical backup (mysqldump,mydumper)

The physical backup (copy,xtrabackup)

Comparison of backup tool differences :

·mysql Replication is relative to other backups , The backup data obtained is relatively real-time .

· Logical backup : It's easier to divide the tables .mysqldump When backing up data, all sql Statements are integrated in the same file ;mydumper When backing up data, it will SQL The statement is split into a single... According to the table sql file , Every sql The file corresponds to a complete table .

· The physical backup : Copy available , Fast .

copy: Copy files directly to the data directory , It may cause table damage or inconsistent data .

xtrabackup about innodb Tables don't need to be locked , about myisam The table still needs to be locked .

10.MySQL How to make a backup plan

It depends on the size of the library . Generally speaking 100G Library in , Consider using mysqldump To do it , because mysqldump More light and flexible , The backup time should be in the low peak period of the business , Full backup can be done every day (mysqldump The backup file is relatively small , Smaller after compression ).

100G The above Library , Consider using xtranbackup To do it , Backup speed is significantly faster than mysqldump Be quick .

Generally, one full-time one week , The rest are backed up incrementally every day , The backup time is the low peak period of the business .

原网站

版权声明
本文为[Gemcoder]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241700363665.html