Web安全分享
1、Web安全——HTML基础
2、Web安全——DIV CSS基础
3、Web安全——JavaScript基础
4、Web安全——PHP基础
5、Web安全——JavaScript基础(加入案例)
6、靶场搭建——搭建pikachu靶场
一·、数据库的基本操作
1、MYSQL登录与退出
D:\phpStudy\MySQL\bin
登陆: 输入 mysql -uroot -p -P3306 -h127.0.0.1
退出的三种方法
mysql > exit;
mysql > quit;
mysql > \q;
语法使用:
数据库的登陆:
Microsoft Windows [版本 10.0.22621.4]
(c) Microsoft Corporation。保留所有权利。
C:\Users\lenovo>mysql -uroot -p123456 -h127.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
这里版本我们可以看到为mysql5.7.26
下面为帮助指令:
mysql> help
For information about MySQL products and services, visit:
http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
https://shop.mysql.com/
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
notee (\t) Don't write into outfile.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.
For server side help, type 'help contents'
mysql>
以及某一个命令在mysql下如何使用查询:
mysql> help use
Name: 'USE'
Description:
Syntax:
USE db_name
The USE db_name statement tells MySQL to use the db_name database as
the default (current) database for subsequent statements. The database
remains the default until the end of the session or another USE
statement is issued:
USE db1;
SELECT COUNT(*) FROM mytable; # selects from db1.mytable
USE db2;
SELECT COUNT(*) FROM mytable; # selects from db2.mytable
The database name must be specified on a single line. Newlines in
database names are not supported.
URL: http://dev.mysql.com/doc/refman/5.7/en/use.html
mysql>
接下来为三种不同的退出方式:
mysql> exit;
Bye
C:\Users\lenovo>
mysql> quit;
Bye
C:\Users\lenovo>
mysql> \q;
Bye
C:\Users\lenovo>
2、MYSQL数据库的一些解释
注意: 数据库就相当于文件夹,表就相当于文件
我们可以看见这里面即为我们创建并使用的数据库,同时打开之后都为很多的表单。
3、MYSQL注释符有三种:
1、#...
2、"-- ..."
3、/*...*/
二、数据库的一些基本操作
1、数据库的增删改查(sql语句)
这里db*
为数据库名称,可随意:
-
增:
create database db1;
-
删:
drop database db1;
-
改:
alter database db1 charset utf8
-
查:
show databases;
#查看所有的数据库
实际操作:
创建数据库:
mysql> create database moondata;
Query OK, 1 row affected (0.00 sec)
查看数据库:
ysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| moondata |
| mydata |
| mysql |
| performance_schema |
| pikachu |
| sys |
+--------------------+
7 rows in set (0.00 sec)
mysql> show create database moondata;
+----------+-------------------------------------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------------------------------------+
| moondata | CREATE DATABASE `moondata` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */ |
+----------+-------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
修改数据库:
mysql> alter database moondata charset utf8;
Query OK, 1 row affected (0.00 sec)
mysql>
删除数据库:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| moondata |
| mydata |
| mysql |
| performance_schema |
| pikachu |
| sys |
+--------------------+
7 rows in set (0.00 sec)
mysql> drop database moondata;
Query OK, 0 rows affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydata |
| mysql |
| performance_schema |
| pikachu |
| sys |
+--------------------+
6 rows in set (0.00 sec)
mysql>
其他命令:
查看指定的数据库 show create database db1;
mysql> show create database moondata;
+----------+-------------------------------------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------------------------------------+
| moondata | CREATE DATABASE `moondata` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */ |
+----------+-------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
设置默认的utf8
,在配置文件中:写上character_set_server = utf8
use db2
select database()
#查看你当前在哪个文件夹
重命名数据库 RENAME
database olddbname TO newdbname
show status;
显示一些系统特定资源的信息,例如,正在运行的线程数量。
desc tabl_name;
显示表结构,字段类型,主键,是否为空等属性,但不显示外键。
show databases
查看这个mysql
里面有多少个库
use mysql
use
选择数据库
show tables
查看当前库里面所有的表
mysql> select password from user where user='root';
Mysql 5.7 select authentication_string,user from mysql.user;
查看当前数据库 里面的表user
用户为root
的密码
alter database
数据库名 character set utf8;
三、table 表的操作
1、查看表结构
desc table
DESCRIBE
表名;
2、查看表的内容
select * from table_name
3、建立表
CREATE TABLE
表名 (
属性名 数据类型 [完整约束条件],
属性名 数据类型 [完整约束条件],
…
…
属性名 数据类型 [完整约束条件]
);
字段名就是属性名
完整的建立表的语句
create table users(id int(7) AUTO_INCREMENT,
username varchar(100) not null,
password varchar(100) not null,
PRIMARY KEY(id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql> create table users(id int(7) UNSIGNED auto_increment,username varchar(30) not null,password varchar(32) not null,email varchar(40),primary key (id))engine=myisam default charset=utf8;
Query OK, 0 rows affected (0.00 sec)
if not exists表示当相同的表名存在时,则不执行此创建语句,避免语句执行错误
create database if not exists [table];
ENGINE=InnoDB DEFAULT CHARSET=utf8;
ENGINE
设置表的引擎 和默认的字符类型
常见的数据库引擎InnoDB myisam
数据类型https://www.cnblogs.com/-xlp/p/8617760.html
4、约束条件
PRIMARY KEY
标识该属性为该表的主键,可以唯一的标识对应的元组FOREIGN KEY
标识该属性为该表的外键,是与之联系某表的主键
NOT NULL
标识该属性不能为空UNIQUE
标识该属性的值是唯一的AUTO_INCREMENT
标识该属性的值是自动增加,这是MySQL的SQL语句的特色DEFAULT
为该属性设置默认值
5、修改表的操作
修改表
格式: ALTER TABLE
旧表名 RENAME
新表名;
修改字段的数据类型:
ALTER TABLE
表名MODIFY
属性名 数据类型;
修改字段名:
ALTER TABLE
表名CHANGE
旧属性名 新属性名 新数据类型;
增加字段名:
ALTER TABLE
表名ADD
属性名1 数据类型 [完整性约束条件] [FIRST | AFTER
属性名2];
删除字段:
ALTER TABLE
表名DROP
属性名;
更改表的存储引擎:
格式:
ALTER TABLE
表名ENGINE =
存储引擎名;
四、数据的增删改查
为表中所有字段添加数据
语法: INSERT INTO
表名(字段名1,字段名2,…)VALUES(值1,值2,…);mysql> insert into users (id,username,password)values(1,'moon','123456');
1、增
语法: INSERT INTO
表名 VALUES(值11,值2,…);mysql> insert into users values(null,'test','123456');
语法: INSERT INTO
表名(字段1,字段2,…)VALUES
(值1,值2,…)
语法: INSERT INTO
表名 SET
字段名1=值1[,字段名2=值2,…]
举例: INSERT INTO student SET id=4,name='zhaoliu',grade=72;
同时添加多条数据
语法:INSERT INTO
表名[(字段名1,字段名2,…)]VALUES
(值1,值2,…),(值1,值2,…),mysql> insert into users (id,username,password)values(null,'moon','123456'),(null,'alex','123456');
:INSERT INTO
表名[(字段名1,字段名2,…)]VALUES
(值1,值2,…),(值1,值2,…),(值1,值2,…)mysql> insert into users values(null,'moon1','123456'),(null,'alex1','123456');
2、删
DELETE FROM
表名 [WHERE
条件表达式delete from users where id=1;
删除全部数据
若 DELETE
语句中没有使用WHERE
语句,则会将表中所有记录都删除。DELETE FROM
表名
删除全部数据的另一种方法——TRUNCATE
3、更新
语法: UPDATE
表名 SET
字段名1=值1,[ ,字段名2=值2,…][ WHERE 条件表达式 ]
update users set password='aaaa' where id=1;
update users set password='123456',username='moon' where id=1
update users set password=456789;
4、查
select * from users;
星号代表所有的字段
查询指定的字段select username,password from users;
- 按条件调节查询
- 按关系来查询
语法: SELECT
字段名1,字段名2,…FROM
表名WHERE
条件表达式
1、in 查询
SELECT * FROM student2 WHERE id IN (1,2,3);
带 BETWEEN AND
关键字的查询select * from users where id not between 1 and 10;
带 DISTINCT
关键字的查询select distinct username from users
like
查询 一般都会给跟着 %
select * from users where username like "%m%" ;
下划线 _ 匹配一个字符select* from users where username like "moo_"
2、and查询
满足多个条件select * from users where id=1 and username='moon';
3、or查询
满足任意一个条件select * from users where id=1 or username='moon';
OR
和 AND
一起使用的情况OR
和 AND
一起使用的时候,AND
的优先级高于 OR
,因此二者一起使用时,会先运算 AND
两边的表达式,再运算 OR
两边的表达式。mysql> select * from users where id >5 and password='123456c' or username='moon1';
4、聚合查询
count
返回行数
select count(*) from users;
select count(id) from users;
COUNT()
返回某列的行数SUM()
返回某列值的和AVG()
返回某列的平均值MAX()
返回某列的最大值MIN()
返回某列的最小值
5、分组查询
如果报错请在 my.ini
添加sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
GROUP BY
mysql> SELECT * FROM users GROUP BY password;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | moon1 | 123456 |
| 1 | moon | 456789 |
+----+----------+----------+
2 rows in set (0.01 sec)
mysql> SELECT * FROM users GROUP BY username;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 2 | alex1 | 456789 |
| 1 | moon | 456789 |
| 3 | moon1 | 123456 |
+----+----------+----------+
3 rows in set (0.01 sec)
使用 LIMIT
限制查询结果的数量
select * from users limit 2,10;
select * from users as u where u.id=1;
为表和字段取别名select username as myname from users;
6、mysql的子查询
-
where
型子查询
(把内层查询结果当作外层查询的比较条件)
select * from users where id in (select id from users where id>10);
-
from
型子查询
(把内层的查询结果供外层再次查询)
select * from (select username,age from users) as agev_a where age>20
select * from (select * from users where id>=10) as age_10;
(select * from users where id>=10)
查询出来的是一个集合 别名为age_10
select * from age_10
-
exists
型子查询
(把外层查询结果拿到内层,看内层的查询是否成立)
select * from users where EXISTS (select * from users where id>1)
7、联合查询
(两个表的查询)
注释: 默认地,UNION
操作符选取不同的值。如果允许重复的值,请使用 UNION ALL
。
当 ALL
随 UNION
一起使用时(即 UNION ALL
),不消除重复行UNION ALL
查询全部 而且不会消除重复的行union
文章来源:https://www.toymoban.com/news/detail-533186.html
SQL UNION ALL
语法union
的用法及注意事项
两次查询的列数必须一致select * from users union select *,1 from news;
文章来源地址https://www.toymoban.com/news/detail-533186.html
CREATE TABLE `news` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) not NULL,
`content` varchar(255) not null,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
insert into news (title,content)values('a1','a1');
到了这里,关于Web安全——数据库mysql学习的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!