当前位置:网站首页>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 -pappear 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 !
边栏推荐
- On Data Mining
- P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
- Thread sleep, thread sleep application scenarios
- Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
- Indicator system of KQI and KPI
- Why do you want to start pointer compression?
- C#(三十)之C#comboBox ListView treeView
- How do we make money in agriculture, rural areas and farmers? 100% for reference
- Ks003 mall system based on JSP and Servlet
- [Massey] Massey font format and typesetting requirements
猜你喜欢

Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM

MySql数据库root账户无法远程登陆解决办法

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

【可调延时网络】基于FPGA的可调延时网络系统verilog开发

Simple blog system

【FPGA教程案例11】基于vivado核的除法器设计与实现
![[meisai] meisai thesis reference template](/img/14/b39e1db0b5b35702508068e028ee5a.jpg)
[meisai] meisai thesis reference template

RT thread -- FTP of LwIP (2)
![Cf464e the classic problem [shortest path, chairman tree]](/img/6b/65b2dc62422a45cc72f287c38dbc58.jpg)
Cf464e the classic problem [shortest path, chairman tree]

C#(二十九)之C#listBox checkedlistbox imagelist
随机推荐
JVM的手术刀式剖析——一文带你窥探JVM的秘密
自动化测试的好处
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
2.1 rtthread pin device details
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
Python book learning notes - Chapter 09 section 01 create and use classes
[FPGA tutorial case 11] design and implementation of divider based on vivado core
Mathematical modeling regression analysis relationship between variables
3分钟带你了解微信小程序开发
Database, relational database and NoSQL non relational database
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
C#(二十八)之C#鼠标事件、键盘事件
cookie,session,Token 这些你都知道吗?
[001] [stm32] how to download STM32 original factory data
Do you know cookies, sessions, tokens?
Cf464e the classic problem [shortest path, chairman tree]
有条件地 [JsonIgnore]

