当前位置:网站首页>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 "!


边栏推荐
- If you dare to write MQ message queue middleware on your resume, you must win these questions!
- 线程池是什么老鸡?
- sql连续登录问题
- Tortoise does not display a green Icon
- Talk about SQL optimization
- There is a time delay for the click event on the mobile terminal. What is the delay time? How to solve it?
- 50 lectures on practical application of R language (34) - practical application cases of curve separation (with R language code)
- PWN攻防世界Level2
- PHP database ODBC
- ArrayList basic operation and add element source code
猜你喜欢

Double click events and click events

sql训练01

Understanding and design of high concurrency
![[issue 259] uncover how count is executed in MySQL?](/img/bc/ee26eba95f408ea887d6aa06301a0b.jpg)
[issue 259] uncover how count is executed in MySQL?

深入解析 Apache BookKeeper 系列:第三篇——读取原理

The method of exporting packages of all components from existing PCBs in Altium Designer

PWN attack and defense world guess_ num

PMP项目管理概述

matlab习题 —— 图像绘制练习

Relationship between EMC, EMI and EMS
随机推荐
Method overload summary
手机开户股票开户安全吗?开户很难么?
Allegro's method of canceling the routing of a good line
sql训练01
LinkedList学习
Regular expression (?: pattern)
Application of fsockopen function
[linear algebra] 1.1 second and third order determinants
Install kibana
兰宝传感科技冲刺科创板:年营收3.5亿 许永童家族色彩浓厚
How to skip time when closing a socket connection_ Wait status of wait
SQL continuous login problem
Lanbao sensor technology rushes to the scientific innovation board: annual revenue of 350million yuan xuyongtong family has a strong color
Overview of PMP project management
今日直播|Apache Pulsar x KubeSphere 在线 Meetup 火热来袭
allegro设置网络飞线以及网络颜色的方法
Prepare for the Blue Bridge Cup - double pointer, BFS
线程池是什么老鸡?
PHP database ODBC
How to add the live video function to the website built by your own live video software (build a live video website)