当前位置:网站首页>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 !
边栏推荐
- [Key shake elimination] development of key shake elimination module based on FPGA
- 2.1 rtthread pin device details
- Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
- MySQL 中的数据类型介绍
- BUAA magpie nesting
- No qualifying bean of type ‘......‘ available
- Exchange bottles (graph theory + thinking)
- Pytoch foundation - (2) mathematical operation of tensor
- Cf464e the classic problem [shortest path, chairman tree]
- Tips for using dm8huge table
猜你喜欢
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
C#(三十一)之自定义事件
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
Viewing and verifying backup sets using dmrman
Pytoch foundation - (1) initialization of tensors
[analysis of variance] single factor analysis and multi factor analysis
KS008基于SSM的新闻发布系统
Ks003 mall system based on JSP and Servlet
JVM的手术刀式剖析——一文带你窥探JVM的秘密
RT thread -- FTP of LwIP (2)
随机推荐
Schnuka: 3D vision detection application industry machine vision 3D detection
Pytoch foundation - (1) initialization of tensors
In Net 6 CS more concise method
Why do you want to start pointer compression?
User experience index system
Schnuka: what is visual positioning system and how to position it
阿里测试师用UI自动化测试实现元素定位
Proof of Stirling formula
Tips for using dm8huge table
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Simple blog system
Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
mysql关于自增长增长问题
[prediction model] difference method model
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
Maxay paper latex template description
Prime protocol announces cross chain interconnection applications on moonbeam
Blue style mall website footer code
C (XXIX) C listbox CheckedListBox Imagelist