当前位置:网站首页>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 .
边栏推荐
- 【Mongodb】READ_ME_TO_RECOVER_YOUR_DATA,数据库被恶意删除
- Wechat side: what is consistent hash? In what scenario? What problems have been solved?
- Research and investment strategy report on China's nano silver wire conductive film industry (2022 Edition)
- Spark 离线开发框架设计与实现
- 2022年高压电工考试模拟100题及在线模拟考试
- 剑指 Offer 13. 机器人的运动范围
- canvas 实现图片新增水印
- It's hard to hear C language? Why don't you take a look at my article (7) input and output
- 详细了解Redis的八种数据类型及应用场景分析
- shopee开店入驻流水如何提交?
猜你喜欢
中国SSD行业企业势力全景图
动态菜单,自动对齐
「ARM 架构」是一种怎样的处理器架构?
2022年安全员-A证考题及答案
2022-06-10 工作记录--JS-获取到某一日期N天后的日期
Based on the codeless platform, users deeply participated in the construction, and digital data + Nanjing Fiberglass Institute jointly built a national smart laboratory solution
The core concept of JMM: happens before principle
[postgraduate entrance examination English] prepare for 2023, learn list8 words
High level application of SQL statements in MySQL database (I)
[personal experiment report]
随机推荐
Solution to the login error of tangdou people
Win10 or win11 printer cannot print
Feign project construction
EPICS record Reference 3 - - field available for all Records
See how sparksql supports enterprise level data warehouse
The extra points and sharp tools are worthy of the trust | know that Chuangyu won the letter of thanks from the defense side of the attack and defense drill!
CDN principle
【个人实验报告】
Visitor tweets tell you which groups are consuming blind boxes
详细了解关于sentinel的实际应用
Sword finger offer 13 Range of motion of robot
Solve the problem of non secure websites requesting localhost to report CORS after chrome94
【武汉大学】考研初试复试资料分享
C#学习两年的增删改查和C#导入导出(去重)案例
非单文件组件
【Mongodb】READ_ ME_ TO_ RECOVER_ YOUR_ Data, the database is deleted maliciously
Servlet
Stop using it indiscriminately. This is the real difference between @validated and @valid!!!
[postgraduate entrance examination English] prepare for 2023, learn list8 words
How to integrate Huawei cloud function services in fluent