当前位置:网站首页>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 .
边栏推荐
- Leetcode: calculate the number of elements less than the current element on the right (sortedlist+bisect\u left)
- ThreadLocal local thread
- Data communication foundation - Ethernet port mirroring and link aggregation
- China solar window market trend report, technical dynamic innovation and market forecast
- Research and investment strategy report on China's nano silver wire conductive film industry (2022 Edition)
- find your present (2)
- vulnhub Vegeta: 1
- 2022-06-10 工作记录--JS-获取到某一日期N天后的日期
- 开发规范~参数校验异常、异常返回提示切面
- 【文本数据挖掘】中文命名实体识别:HMM模型+BiLSTM_CRF模型(Pytorch)【调研与实验分析】
猜你喜欢

Future development of education industry of e-commerce Express

2022-06-16 工作记录--JS-判断字符串型数字有几位 + 判断数值型数字有几位 + 限制文本长度(最多展示n个字,超出...)

【Mongodb】READ_ ME_ TO_ RECOVER_ YOUR_ Data, the database is deleted maliciously

【个人实验报告】

Cases of addition, deletion, modification and search of C # learning for two years and C # import and export (de duplication)

The core concept of JMM: happens before principle

环境配置 | VS2017配置OpenMesh源码和环境

动态菜单,自动对齐

JWT(Json Web Token)

结构体的内存对齐
随机推荐
Firewall working principle and detailed conversation table
2022-06-10 work record --js- obtain the date n days after a certain date
【WSL】SSH 远程连接及宿主机端口转发配置
2022-06-16 工作记录--JS-判断字符串型数字有几位 + 判断数值型数字有几位 + 限制文本长度(最多展示n个字,超出...)
Leetcode: push domino (domino simulation)
Extend your kubernetes API with aggregated apiserver
[postgraduate entrance examination English] prepare for 2023, learn list8 words
AttacKG: Constructing Technique Knowledge Graph from Cyber Threat Intelligence Reports代码复现
剑指 Offer 13. 机器人的运动范围
Combine pod identity in aks and secret in CSI driver mount key vault
nuScenes——数据集配置过程中遇到图像文件缺失或大小为0时的补救方法
【nvm】
[WSL] SSH Remote Connection and host port forwarding configuration
Annotation
源码阅读 | OpenMesh读取文本格式stl的过程
win10或win11打印机无法打印
Fanuc robot_ Introduction to Karel programming (1)
是否需要提高代码阅读能力?这有技巧
Leetcode algorithm The first common node of two linked lists
非单文件组件