当前位置:网站首页>Mysql database foundation

Mysql database foundation

2022-07-23 10:54:00 GSX_ MI

Catalog

1. What is a database

2. Mainstream databases

3. Basic use

4.Mysql framework

5.SQL classification

6. Storage engine

7. Add


 

1. What is a database

(1) Just use a file to store data , Why get a database ?
① File saving data has the following disadvantages :
  • 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
② Database storage media :
  • disk
  • Memory
(2) In order to solve the above problems , Experts design things that are more conducive to managing data —— database , It can manage data more effectively . The level of database is an important indicator to measure the level of a programmer .
                
                
                

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 .
database server 、 The relationship between database and table is as follows :

                 

(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

                 

                 

原网站

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