当前位置:网站首页>Basic MySQL database operations
Basic MySQL database operations
2022-06-29 02:58:00 【The way to remedy】
One 、 Connect to database
1、 Local connection
(1) command :mysql -uroot -p

(2) command :mysql -h ip( This machine ) -uroot -p

If the following error occurs :
![]()
reason : Not assigned to this ip Address login mysql Database permissions .
resolvent :

(3) command :mysql -hlocalhost -uroot -p

(4) command :mysql -h127.0.0.1 -uroot -p

2、 Remote connection
command :mysql -h ip( The host address where the database is installed ) -uroot -p
There is an error :

resolvent : Perform the following operations on the host with the database installed .

Two 、 Operating the database
MYSQL Database operation foundation
1、 Connect to database . Enter the command :mysql -h ip -uroot -p;

2、 Displays the names of all databases in the system . command :show databases;

3、 New database student.

4、 Using a database student.

5、 In the database student Create a table result. command :create table result(id int(8), name varchar(20), city varchar(20), score int(5));

6、 Add data to the table . command :
insert into result(id,name,city,score) values(1,"wang","beijing",75);
insert into result(id,name,city,score) values(3,"li","shanghai",80);
insert into result(id,name,city,score) values(5,"chen","fuzhou",70);
insert into result(id,name,city,score) values(2,"zhou","xian",90);
insert into result(id,name,city,score) values(7,"han","guangzhou",65);

7、 Delete a piece of data in the table . command :delete from result where id=7;

8、 Modify table result One of the data in . command :update result set score=60 where id=5;

9、 Query the data in the table .
(1) Query all fields in the table . command :select * from result;

(2) Look up name and score Field . command :select name,score from result;

(3) Inquire about name by li Students' scores . command :select score from result where name="li";

MYSQL Advanced operation
1、order by
(1) take result The data in the table is calculated according to the score (score) Sort from high to low ;
command :select * from result order by score desc;
among ,desc Representation of descending order ( Decline ); If from low to high ( Ascending ) Arrange , Then you can put desc Switch to asc: If you don't add this parameter , By default, they are arranged in ascending order .

(2) command :select id,name,score from result order by 1; Display with id The result of ascending order .

command :select id,name,score from result order by 2; Display with name The result of ascending order !

command :select id,name,score from result order by 3; Display with score The result of ascending order !

![]()
It can be concluded from the above results that , For the following commands :select c1,c2,.. . ,cn from result order by M;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
(1)limit M,N. Says from the first M+1 Data starts , Query down in sequence N Data .

(2)limit M. Indicates before query M Data .

3、union select
(1) command :select* from result union select 1,2,3,4; The query result of this statement , That is select * from result and select 1,2,3,4 Splicing of query results .

(2) command :select id,name,score from result union select 1,2,3;

(3)select id,name,score from result union select 1,2;
![]()
(4)select id,name,score from result union select 1,2,3,4;
![]()
From the above results, we can sum up , For the following commands :select c1,c2,. . .,cn from result union select d1,d2, . . .dm; 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 .
(5)select id,city from result where id=1 and 1=2 union select name,score from result;

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、information_schema database
(1)MySQL (MariaDB)5.5 The above version comes with information_schema 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 . You can put information_schema Database as MySQL(MariaDB) Of “ Catalog "!


边栏推荐
- Altium Designer中从已有的PCB中导出所有元件的封装的方法
- priority_ Understanding of queue
- 逆序对对数计算,顺序对对数计算——归并排序
- Pat class a a1057 stack
- Kubernetes: container resource requirements and constraints (constraints)
- 18. `bs对象.节点名.next_sibling` 获取兄弟节点
- Tortoise does not display a green Icon
- The method of exporting packages of all components from existing PCBs in Altium Designer
- PWN beginner level0
- Tortoise 没有显示绿色图标
猜你喜欢

What is a thread pool?

18. `bs对象.节点名.next_sibling` 获取兄弟节点

双击事件与单击事件的那些事

Has Moore's law come to an end?

Have you learned the common SQL interview questions on the short video platform?

The thinkphp5.1 runtime file has been changed to 777 permission, but cannot be written
![[Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre](/img/ea/70b59c64d3287a887e371a9181fe45.png)
[Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre

LinkedList learning

Install kibana

Tortoise does not display a green Icon
随机推荐
[linear algebra] 1.2 total permutation and commutation
99乘法表
18. `bs對象.節點名.next_sibling` 獲取兄弟節點
正则表达式(?:pattern)
The method of displaying or closing the network flying line in Allegro design
Solve the problem that the cursor flashes after clicking a point when measuring the distance in Allegro
[Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre
SQL training 01
allegro 设计中显示网络飞线或关闭网络飞线的方法
[線性代數] 1.1 二階與三階行列式
sql训练01
Bluetooth solution | Lenz technology Amazon direct connected magic lantern solution
18. `bs object Node name next_ Sibling` get sibling nodes
Map and set use pari as the key value. How to define
[issue 259] uncover how count is executed in MySQL?
兰宝传感科技冲刺科创板:年营收3.5亿 许永童家族色彩浓厚
Concise words tell about technical people who must master basic IT knowledge and skills. Part 1
Redu.us took the initiative to transform, and the operation leader of China's charging pile emerged
PAT甲级 A1057 Stack
矩阵特征值和特征向量求解——特征值分解(EVD)