当前位置:网站首页>Fundamentals of SQL database operation
Fundamentals of SQL database operation
2022-07-06 03:58:00 【Z_ l123】
One 、MySQL Basic operation
1. Connect to database
stay MySQL Of bin Under the table of contents cmd
Enter the command
mysql -uroot -p
appear Enter password Tips , Enter the password to log in
2. Displays the names of all databases in the system
show databases;
Be careful : most SQL Commands end with a semicolon !!!
2. New database boke
create database boke;
4. Using a database boke
use boke;
5. In the database boke Create a table artical
create table artical(id int(8),name varchar(20),score int(5));
6. In the table boke Add data to
insert into artical(id,name,score) values(3,"aa",10);
insert into artical(id,name,score) values(6,"cc",56);
insert into artical(id,name,score) values(1,"ee",63);
insert into artical(id,name,score) values(4,"jj",98);
insert into artical(id,name,score) values(2,"vv",75);
insert into artical(id,name,score) values(5,"qq",69);
Be careful : If the data is character type (varchar), You must use single or double quotation marks to wrap !!!
7. Query the data in the table
Query all
select * from artical;
Inquire about id=5 Of score
select score from artical where id=5;
8. Delete a piece of data
Delete id=6 The data of
delete from artical where id=6;
9. Modify a piece of data
modify id=5 The data of , Put it score Set to 30
update artical set score=30 where id=5;
Two 、MySQL Advanced operation
1.order by Usage of
(1) take result The data in the table are based on score Sort from low to high :
select * from artical order by score asc;
among ,asc Expressing ascending order ( Increasing ); If from high to bottom ( Descending ) Arrange , Then you can put asc Switch to desc; If you don't add this parameter , By default, they are arranged in ascending order .
(2) Try the following commands :
select id,name,score from artical order by 1;
Normal display with id The result of ascending order
select id, name,score from artical order by 2;
Normal display with name The result of ascending order
select id, name,score from artical order by 3;
Normal display with score The result of ascending order
select id, name,score from artical order by 4;
Be careful :order by Back number (M) Must be less than or equal to n( Number of fields in database query ), To display properly . If M>n, The database will report an error . This feature can be used to judge the number of fields queried in the database !!!
2.limit Usage of
The basic format is :
limit M,N // Says from the first M+1 Data starts , Query down in sequence N Data
limit M // Indicates before query M Data
In the query table 3,4 Data
select* from artical limit 2,2;
The first... In the query table 3 Data
select * from artical limit 3;
3.union select Usage of
select * from artical union select 1,2,3;
The query result of this statement , That is select * from artical and select 1,2,3 Splicing of query results
Try the following 2 statement :
select id,name from artical union select 1,2;
Normal display !
select id,name from artical union select 1,2,3;
Report errors !
Be careful : The second half of the sentence union select Number of fields queried (m) Must be the same as the first half of the sentence select Number of fields queried (n) equal , The database can display the results normally . And order by be similar , This feature can be used to judge the number of fields queried in the database !!!
select id,name from artical where id=1 and 1=2 union select name,score from artical;
From the above results, we can sum up , When the field name is known , An attacker simply places the field anywhere it can be displayed , You can expose the value of this field .
4.union select combination information_schema database
MySQL5.0 There is a version called information_schema The database of , It stores all the information in the database , It's about MySQL Information about all other databases maintained by the server . Such as database name , Table of database , Data type and access right of table column . and 5.0 There is no . You can put information_schema Database as MySQL The catalog of .
show databases;
select schema_name from information_schema.schemata;
The execution results of the two statements are the same !
use boke;
show tables;
select table_name from information_schema.tables where table_schema='boke';
The execution results of the two groups of statements are the same !
边栏推荐
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- JVM的手术刀式剖析——一文带你窥探JVM的秘密
- C#(二十八)之C#鼠标事件、键盘事件
- MySQL 中的数据类型介绍
- RT thread -- FTP of LwIP (2)
- KS003基于JSP和Servlet实现的商城系统
- Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
- [adjustable delay network] development of FPGA based adjustable delay network system Verilog
- [PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
- 简述C语言中的符号和链接库
猜你喜欢
Tips for using dm8huge table
An article will give you a comprehensive understanding of the internal and external components of "computer"
How do we make money in agriculture, rural areas and farmers? 100% for reference
Multi project programming minimalist use case
C (thirty) C combobox listview TreeView
MySQL about self growth
Ks003 mall system based on JSP and Servlet
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
cookie,session,Token 这些你都知道吗?
随机推荐
Ks003 mall system based on JSP and Servlet
Do you know cookies, sessions, tokens?
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
51nod 1130 n factorial length V2 (Stirling approximation)
asp. Core is compatible with both JWT authentication and cookies authentication
Use js to complete an LRU cache
BUAA calculator (expression calculation - expression tree implementation)
mysql关于自增长增长问题
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
LTE CSFB test analysis
Oracle ORA error message
20、 EEPROM memory (AT24C02) (similar to AD)
Ipv4中的A 、B、C类网络及子网掩码
MySQL master-slave replication
Schnuka: visual positioning system working principle of visual positioning system
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
有条件地 [JsonIgnore]
cookie,session,Token 这些你都知道吗?
Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)