当前位置:网站首页>Basic knowledge about SQL database
Basic knowledge about SQL database
2022-07-03 07:10:00 【L gold p】
1 data (data)
2 database (database)
database : seeing the name of a thing one thinks of its function , Is the warehouse used to store data .
The reason for the poor cross platform performance of files is whether the storage methods between operating systems are different , So why can the database solve ?
A collection of data that follows a certain data format .
characteristic : You can think of it as an improvement on the file system . It solves the problem between different operating systems , Compatibility of data formats . in other words , As long as it is a data file of the same database , Even from Windows Moved to Linux On , It can also be handled normally .
Classification of database 
Oracle
This is a relational database . It is characterized by closed source charging , But powerful and stable , And there is a professional technical support team . Large enterprises generally use this kind of database 、 banking 、 The financial sector .
MySQL
It is also a relational database . It is characterized by open source and free , The function is still good , It's also relatively stable . This kind of database is usually used , Small and medium-sized enterprises, etc . Because it's open source , So some of our enterprises can customize it 、 Secondary development , To support their special business . For example, Ali. . It is said to be the most widely used DBMS, yes MySQL Customized secondary development of , It's also easier to use .
Redis
Redis It's a non relational database (Not Only SQL). It is commonly used K-V Store data in the form of key value pairs , The usage scenario is cache ( It can be used as a supplement to relational database ). Memory based , The data is all in memory , So the access speed should be fast .Redis It also provides a mechanism for periodic serialization to disk , its IO The performance is also very high .
MongoDB
This is also NOSQL database . It stores data in the form of documents . It stores data in the form of documents . Use scenarios , It is usually a large amount of data with high concurrent access . Its performance is also very high .
The relationship between relational database and non relational database
MySQL brief introduction
MySQL Is a relational database management system , The Swedish MySQL AB Companies to develop , At present belongs to the Oracle Its products .MySQL Is one of the most popular relational database systems , stay WEB Application aspect ,MySQL It's the best RDBMS(Relational Database Management System, Relational database management system ) One of the application software .
MySQL Is a relational database management system , Relational databases keep data in different tables , Instead of putting all the data in one big warehouse , This improves flexibility and accuracy .
MySQL What is used SQL Language is the most commonly used standardized language for accessing database .MySQL The software adopts a dual licensing policy , It is divided into community version and commercial version , Because of its small size 、 Fast 、 Low total cost of ownership , Especially open source , In general, small and medium-sized sites are chosen for development MySQL As website database .
Database objects :
surface , View , function , stored procedure , Index, etc. .
surface
It's where data is stored , There are records in it , Records are made up of fields . Each field has its own field name 、 field value 、 Field type ( data type ). Fields are the basic unit for storing data . similar Java Objects in the , For storing data .
View
We can understand it as a virtual table ( It doesn't really exist on physical disks ). The view is based on select The result set generated by the statement query . When one select When the statement is complex and the call frequency is high , We don't want to write the sentence again , At this time, you can put this select Statement is created as a view . Every time you use a view , You can use it as a watch .
function
It is usually the implementation of a function , Most of us use system functions (MYSQL Provided ), We can also customize functions . Its calling routine is through the use of select Function name ( Parameters 1, Parameters 2..); To call . It has only one return value .
stored procedure
It is also the realization of a function . What we call database programming ,SQL Statement programming , It mainly refers to customizing a stored procedure . Calling a stored procedure uses exec Stored procedure name Parameters 1 Wait to call . It can return multiple values , There can be no return value .
Indexes
We've been in contact with , It's like a book catalog , It is established to speed up our query .
MySQL Use
1 User creation and Authorization
CREATE USER 'tianliang'@'127.0.0.1' IDENTIFIED BY 'tianliang';
GRANT ALL PRIVILEGES ON *.* TO 'tianliang'@'127.0.0.1';
FLUSH PRIVILEGES;
The above is to set all permissions for users
Format :grant jurisdiction on Database name . Table name to user @ Log on to the host identified by " User password ";*.* Represents all databases and all tables ;
@ After that is the visit MySQL The client of IP Address ( or Host name ) % On behalf of any client , If filled in localhost For local visits ( Then this user can't access it remotely mysql Database ).
GRANT ALL PRIVILEGES ON _08_.* TO 'tianliang'@'%' ;
hold _08_ Operation permissions of the database , Authorized to tianliang user
All privileges It's all rights
GRANT select,insert,update,drop,create,delete ON _08_.* TO 'c'@'%' ;
The above is to set the query at the same time , add to , Update and other operations
Of course Or just write select , Yes, you can only query
Select Inquire about
Insert insert data
Update Update data
Delete Delete data
Drop Delete table
Create Create table
Cancel the authorization
revoke Follow grant The syntax is similar , Just put the keywords “to” Switch to “from” that will do :
grant all on *.* to [email protected];
revoke all on *.* from [email protected];
2 Database creation and deletion
View the currently linked MySQL Server version
select version();
Displays the of the current link MySQL All the databases in the server
show databases;
Output specified content , String needs to be enclosed in single quotation marks , It doesn't distinguish between characters or strings , Just use single quotation marks , The value can be written directly
select ‘xxxx’;
Set field name
select ‘xxxx’ as Field name ;
as You can omit it
select ‘xxxx’ Field name ;
Switch database
use test;
View all tables under the current library , When using this command , Usually followed by use xxx; Switch database , If the current command line , Not opened in the Library , Use it directly show tables Will report a mistake
show tables;
Create a new library on the current database server
create database day01;
Delete a library on the current database server
drop database day01;
3 Table creation and deletion
In the database day01 Create the table below student_info
use day01;
create table student_info (
id int,
`name` varchar(20),
salary decimal(18,2)
)ENGINE = innodb default charset = utf8;
-- In the database day01 Delete table below student_info
use day01;
drop table student_info;
// add if not exists Can prevent statement errors , If this table exists, it will not be created , But there is no error
create table if not exists employee (
id int(32) primary key auto_increment,
name varchar(32),
empNo char(6),
deptNo char(3),
telephone char(11),
homeplace varchar(128),
joinDate datetime
)
4 char and varchar Use
In the database day01 Create the table below student_info
use day01;
create table t_student (
id int,
`name` varchar(20),
phone char(11)
)ENGINE = innodb default charset = utf8;
-- In the database day01 Delete table below student_info
use day01;
drop table student_info;
5 DML operation
create table teacher (
id int,
`name` varchar(20),
salary decimal(18,2)
)ENGINE = innodb default charset = utf8;
insert into teacher (name, id, salary) values (' Lao Liu ',1,56.23);
insert into teacher (name, salary) values (' Lao Wang ',56.23);
Delete Lao Wang
delete from teacher where name=' Lao Wang ';
Delete id Empty (null)
delete from teacher where id is null;
change id by 1 Of name and salary
update teacher set salary=1000.45, name='dave' where id = 1;
Bear in mind Whether it's delete still update, As long as you are sure that it is not a full table operation , You have to use it where Conditions !!!
DQL( Data query language )
Format :
select Column qualification from Table limit where Row qualification
select student_name from student_info where student_age=23;
select * from student_info;
边栏推荐
- Class and object summary
- Interfaces and related concepts
- [set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
- Practice of enterprise ab/testing platform
- 10 000 volumes - Guide de l'investisseur en valeur [l'éducation d'un investisseur en valeur]
- mysql误删root账户导致无法登录
- Win 10 find the port and close the port
- Distributed ID
- Sorting out the core ideas of the pyramid principle
- 【已解决】win10找不到本地组策略编辑器解决方法
猜你喜欢
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
Software testing assignment - day 1
Software testing assignment - the next day
Common APIs
La loi des 10 000 heures ne fait pas de vous un maître de programmation, mais au moins un bon point de départ
Inno setup production and installation package
4279. 笛卡尔树
dataworks自定義函數開發環境搭建
Reading notes of "learn to ask questions"
POI excel percentage
随机推荐
Advanced API (UDP connection & map set & collection set)
Error c2017: illegal escape sequence
Software testing learning - the next day
Thoughts in Starbucks
mongodb
Final, override, polymorphism, abstraction, interface
萬卷書 - 價值投資者指南 [The Education of a Value Investor]
JMeter JSON extractor extracts two parameters at the same time
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
Use the jvisualvm tool ----- tocmat to start JMX monitoring
Getting started with pytest
How to plan well?
JMeter test result output
centos php7.2.24升级到php7.3
Software testing assignment - day 3
Stream stream
[Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
instanceof
La loi des 10 000 heures ne fait pas de vous un maître de programmation, mais au moins un bon point de départ
Setting up the development environment of dataworks custom function