当前位置:网站首页>Mysql database foundation
Mysql database foundation
2022-07-23 10:54:00 【GSX_ MI】
Catalog
1. What is a database
- File security issues
- Files are not conducive to data query and management
- Files are not conducive to storing large amounts of data
- It's not convenient to control the file in the program
- disk
- Memory
2. Mainstream databases
- SQL Sever: Microsoft products ,.Net Programmer's favorite , Medium and large scale projects .
- Oracle: Oracle products , Suitable for large projects , Complex business logic , Concurrency is generally not as good as MySQL.
- MySQL: The world's most popular database , It belongs to Oracle , Good concurrency , Not suitable for complex business . Mainly used in e-commerce ,SNS, Forum . For the simple SQL The treatment effect is good .
- PostgreSQL : A relational database developed by the computer department of the University of California, Berkeley , Whether it's for private use , commercial , Or for academic research , Free to use , Modify and distribute .
- SQLite: It's a lightweight database , Abide by ACID Database management system based on RDBMS , It's contained in a relatively small C In the library . Its design The target is embedded , And it has been used in many embedded products , It takes up very low resources , In embedded devices , can It only takes a few hundred K That's enough memory .
- H2: It's a use. Java Development of embedded database , It itself is just a class library , It can be directly embedded into the application project .
3. Basic use
(1) Link server
mysql -h 127.0.0.1 -P 3306 -u root -p
- If not -h 127.0.0.1 The default is to connect locally
- If not -P 3306 Connection by default 3306 Port number
- mysql The client can connect to the server across the network
Successful connection :
(2) The server , database , Table relations
- Installing a database server , Just in the machine On Installed a database management system program , This management program can manage multiple databases , Generally, developers will create a database for each application .
- To save the data of the entity in the application , Generally, multiple tables will be created in the database , To save data for entities in the program .

(3) Use cases
① Create database
create database mysql_test;
1) The files created by the database will be generated under this path , This path is mysql In the configuration file

2) Create a database , The essence is to create a directory under the data path of the database

② Using a database
use mysql_test;
- use = cd , Enter the directory of the database
- Before creating the table , Be sure to enter the database first
③ Create database tables
create table student(
id int,
name varchar(32),
gender varchar(2)
);1) There are two more files in the database path . The essence of creating a table structure : In the specified database directory , Just create a new ordinary file !

2) View table structure


④ Insert data and query
insert into student (id, name, gender) values (1, ' Zhang San ', ' male ');
insert into student (id, name, gender) values (2, ' Li Si ', ' Woman ');
insert into student (id, name, gender) values (3, ' Wang Wu ', ' male '); 
4.Mysql framework

MySQL Server The architecture can be divided into network connection layer from top to bottom 、 Service layer 、 Storage engine layer and system file layer .
(1) Network connector
Client connector (Client Connectors): Provide with MySQL Server built support . At present, almost all the mainstream server programming technologies are supported , For example, common Java、C、Python、.NET etc. , They do it through their own way API Technology and MySQL Establishing a connection .
(2) Service layer (MySQL Server)
- Connection pool (Connection Pool): Responsible for storing and managing the connection between client and database , A thread is responsible for managing a connection .
- System management and control tools (Management Services & Utilities): Like backup restore 、 security management 、 Cluster management, etc .
- SQL Interface (SQL Interface): Used to accept all kinds of messages sent by clients SQL command , And returns the result of the query that the user needs . such as DML、DDL、 stored procedure 、 View 、 The trigger etc. .
- Parser (Parser): Responsible for transferring the requested SQL Parse to generate a " The parse tree ". Then according to some MySQL The rule further checks that the parse tree is legal .
- Query optimizer (Optimizer): When “ The parse tree ” After passing the parser syntax check , It's up to the optimizer to translate it into an execution plan , And then interact with the storage engine .
- cache (Cache&Buffer): Caching mechanism is composed of a series of small caches . For example, table caching , Record the cache , Permission cache , Engine cache, etc . If the query cache has a hit query result , The query statement can directly query the cache to fetch data .
(3) Storage engine layer (Pluggable Storage Engines)
The storage engine is responsible for MySQL Data storage and extraction in , Interact with the underlying system files , Really add, delete, check and modify files .MySQL The storage engine is plug-in , The query execution engine in the server communicates with the storage engine through the interface , Interfaces mask the differences between different storage engines . Now there are many kinds of storage engines , Each has its own characteristics , The most common is MyISAM and InnoDB.
(4) System file layer (File System)
This layer is responsible for storing the data and logs of the database on the file system , And complete the interaction with the storage engine , It's the physical storage layer of the file . It mainly contains log files , Data files , The configuration file ,pid file ,socket Documents, etc. .
5.SQL classification
①DDL【data definition language】 Data definition language , Used to maintain stored data structure
For instructions : create, drop, alter
②DML【data manipulation language】 Data manipulation language , Used to correct data To operate
For instructions : insert,delete,update
- DML There is another one in the DQL, Data query language , For instructions : select
③DCL【Data Control Language】 Data control language , Mainly responsible for authority management and affairs For instructions : grant,revoke,commit
6. Storage engine
(1) The storage engine is : How database management systems store data 、 How to index and update stored data 、 Query data and other technologies . MySQL The core of is the plug-in storage engine , Support for multiple storage engines
(2) View storage engine

7. Add
(1) What is a database : It is a complete set of data storage disaster recovery solutions .
(2) Look at the database server

- mysql service : The essence is the relationship between network service process and file !
- The client just sends the statement to the server , The service process helps us with various file operations .
- mysql In essence, it is also a network service
(3) Stop and restart mysql The server
(4) It's usually inside the enterprise
- MySQL It cannot be exposed on the public network
- MySQL Generally, the service port will be changed
(5)mysql If the connection is successful, some commands can be executed

- system clear : Clear the screen
边栏推荐
- 动态内存管理
- R language uses DALEX package to explain and analyze the machine learning model built by H2O package: summary and Practice
- Anaconda虚拟环境下安装opencv报错的问题
- 排序
- TS type gymnastics intermediate type gymnastics challenge closing battle
- Redis source code and design analysis -- 7. Quick list
- JMeter record the BeanShell written into excel instance caused by an automatic data generation
- 部署metersphere
- 【无标题】
- Deploy metersphere
猜你喜欢

Jump statement and debugger
TS type gymnastics intermediate type gymnastics challenge closing battle

“我最想要的六种编程语言!”

mysql log理解

The wave of the meta universe is shocking. Seize the opportunity and work together

When flutter runs flutter pub get, it reports an error: "the client does not have the required privileges“

Question 300 Leçon 6 type quadratique

Redis源码与设计剖析 -- 12.集合对象

Reading the thesis "sentence embeddings using Siamese Bert networks"

Redis source code and design analysis -- 7. Quick list
随机推荐
20.有效的括号
Redis源码与设计剖析 -- 6.压缩列表
Redis source code and design analysis -- 10. List object
微信小程序封装wx.request
12 open source background management systems suitable for outsourcing projects
【社媒营销】出海新思路:Whatsapp Business替代Facebook
Meituan's 8-year experience on how to improve test engineers (automation, performance, test development)
Thing JS notes
mysql的索引的操作
组件中的自定义事件
SVG, canvas, drawing line segments and filling polygon, rectangle, curve drawing and filling
Analysis of network security level protection 2.0 standard
IO应知应会
An analysis of the CPU explosion of an intelligent transportation background service in.Net
Niuke brush questions - Sword finger offer (phase II)
软件测试基本概念篇
Reading the thesis "sentence embeddings using Siamese Bert networks"
【Unity】AVPro使用踩坑,编辑器模式使用视频播放正常,打包后视频无法播放的问题
Question 300 Leçon 6 type quadratique
TZC 1283: simple sort - heap sort