当前位置:网站首页>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 !
边栏推荐
- Data analysis Seaborn visualization (for personal use)
- 登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
- Record the pit of NETCORE's memory surge
- C (XXIX) C listbox CheckedListBox Imagelist
- Microkernel structure understanding
- Pytoch foundation - (1) initialization of tensors
- Record the pit of NETCORE's memory surge
- Differential GPS RTK thousand search
- C#(三十一)之自定义事件
- 1. New project
猜你喜欢
Recommended papers on remote sensing image super-resolution
Suggestions for new engineer team members
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
[FPGA tutorial case 11] design and implementation of divider based on vivado core
RT thread -- FTP of LwIP (2)
C (XXIX) C listbox CheckedListBox Imagelist
Maxay paper latex template description
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
How to modify field constraints (type, default, null, etc.) in a table
记一次excel XXE漏洞
随机推荐
Conditionally [jsonignore]
C language -- structs, unions, enumerations, and custom types
Prime Protocol宣布在Moonbeam上的跨链互连应用程序
Containerization Foundation
Do you know cookies, sessions, tokens?
cookie,session,Token 这些你都知道吗?
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
DM8 backup set deletion
C (XXIX) C listbox CheckedListBox Imagelist
2.1 rtthread pin device details
Tips for using dm8huge table
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
MySQL master-slave replication
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
asp. Core is compatible with both JWT authentication and cookies authentication
Interface idempotency
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
Proof of Stirling formula
【按鍵消抖】基於FPGA的按鍵消抖模塊開發