1 工具? phpstudy 的使用
MySQL是一种开源的关系型数据库管理系统(RDBMS),是最流行和广泛使用的数据库系统之一。以下是MySQL的一些主要特点和功能:
-
开源性:MySQL是开源软件,可以免费使用和修改。
-
可靠性:MySQL具有良好的稳定性和高可靠性,经过了广泛的测试和实践,被广泛应用于大型企业和互联网应用。
-
性能优化:MySQL具有高效的性能,可以处理大规模的数据和高并发访问。它采用了多种优化策略,如索引、缓存、查询优化等,以提高数据库的查询效率和响应速度。
-
多线程:MySQL支持多线程处理,能够同时处理多个客户端的请求,提高了数据库的并发处理能力。
-
支持多种数据类型:MySQL支持多种数据类型,包括整数、浮点数、日期、字符串、二进制等,以适应不同类型的数据存储需求。
-
安全性:MySQL提供了多种安全措施来保护数据的安全性,包括用户权限管理、加密传输、防火墙等。
-
数据备份和恢复:MySQL提供了备份和恢复工具,可以方便地进行数据备份和恢复操作,保证数据的安全和可靠性。
-
数据复制和集群:MySQL支持数据复制和集群部署,可以实现数据的自动备份和故障切换,提高数据库的可用性和可扩展性。
MySQL完整语句 mysql所有语句_mob6454cc6e6a40的技术博客_51CTO博客
- 增加数据: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
- 示例: INSERT INTO students (name, age, gender) VALUES ('Tom', 20, 'Male');
- 删除数据: DELETE FROM table_name WHERE condition;
- 示例: DELETE FROM students WHERE id = 1;
- 更新数据: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
- 示例: UPDATE students SET age = 25, gender = 'Female' WHERE id = 1;
- 查询数据: SELECT column1, column2, ... FROM table_name WHERE condition;
- 示例: SELECT name, age, gender FROM students WHERE id = 1;
小皮面板(phpstudy) - 让天下没有难配的服务器环境! (xp.cn)


#1.创建数据库
create database tedudb;

#2 设置为当前数据库.
use tedudb;

#3.创建数据库中的数据表
create table admin(
?????? id int unsigned auto_increment,
?????? name varchar(200) not null,
?????? pwd varchar(64) not null,
?????? primary key(id)
);
create table book(
?????? id int unsigned auto_increment,
?????? title varchar(200) not null,
?????? price decimal(10,2) not null,? ?
?????? publisher varchar(200) not null,
?????? primary key(id)
);

#4 在表中插入数据
# 向admin表插入数据
insert into admin(name,pwd)values('tarena','123.com');
insert into admin(name,pwd)values('ntd2304','456.com');
insert into admin(name,pwd)values('mazg','789.com');
insert into admin(name,pwd)values('admin','789.cn');

# 向book表插入数据
insert into book(title,price,publisher)values('sql基础',80,'清华大学出版社');
insert into book(title,price,publisher)values('渗透测试实战',90,'清华大学出版社');
insert into book(title,price,publisher)values('红楼梦',85,'北京大学出版社');
insert into book(title,price,publisher)values('应急响应实战',60,'清华大学出版社');
insert into book(title,price,publisher)values('三国演义',65,'北京大学出版社');
insert into book(title,price,publisher)values('渗透测试基础',50,'清华大学出版社');

#5 删除数据库的数据表
#drop table admin;
#drop table book;
#删除数据库
#drop database tedudb;
#6 查询数据库的数据表
use tedudb;

# 1.查询整张表
select * from admin;

select * from book;

# 2.查询指定列(字段)的数据
select name,pwd from admin;

select title,price from book;

# 3.查询指定行的数据(指定条件)
# 3.1 登录验证的查询
select * from 表名 where(条件)name(姓名)='tedu'and pwd='123456' 两个条件符合即可
select * from admin where name='tedu' and pwd='123456';
?

select * from 表名 where title='渗透测试实战' or price=50; 一个条件符合即可
select * from book where title='渗透测试实战' or price=50;

# 3.2 排序
# 升序排列
select * from book order by price;

# 降序排列
select * from book order by price desc;

# 4 查询价格在 [60,80]的图书
select * from book where price<=80 and price>=60;

# between m? and n? 查询
select * from book where price between 60 and 80;

# 5 查询id值>5的图书
select * from book where id>5;

select * from book where price>=60;

# 6 查询北京大学出版社并且价格大于80的图书
select * from book where publisher='北京大学出版社' and price>80;

# 7 模糊查询
# % 表示零个或多个字符?? _表示一个字符。无论是汉字还是字母都是字符
select * from admin;

# 8 以字母 t开头查询条件
select * from admin where name like 't%';
# 9 包含字母 m的字母的条件
select * from admin where name like '%m%';

select * from book;
# 3条
select * from book where title like '%基础';
# insert into book(title,price,publisher)values('编程基础',55,'清华大学出版社');
# 1条
select * from book where title like '__基础';
# 2条
select * from book where title like '___基础';
# 5. limit
# 5.1? limit m??? #m表示数据的数量
# 5.2? limit n,m? # n表示从第几条记录开始, 0
select * from book limit 5;
select * from book limit 0,3;
select * from book limit 3,3;
select * from book limit 6,3;

# 6.使用tedudb数据库
use tedudb;
# 修改操作
# 6.1.修改tedu用户的密码
update admin set pwd='admin.net' where name='tedu' and pwd='123456';
select * from admin where name='tedu';
# 6.2.行情好,所有的图书涨价10元
update book set price=price+10;
select * from book;
# 6.3.文学方面的书滞销,将北京大学出版社的图片降价5元
update book set price=price-5 where publisher='北京大学出版社';
select * from book;
# 删除数据(不能包含列信息)
delete from book where id=5;
delete from book;
select * from book;
#7 使用的数据库是pikachu
use pikachu;

#7.1 查看数据库的表名 pikachu.member
select * from pikachu.member;
#7.2 查看数据库的表名 性别='男/女';
select * from pikachu.member where sex='girl';
select * from pikachu.member where sex='boy';
#7.3 查看数据库的表名 id>'num';
select * from member where id>=5;
select * from member where id!=3;
#7.4 查看数据库的表名id 为 2 4 6 8
select * from member where id in (2,4,6,8);
#7.5 查看数据库的表名不是id 为 2 4 6 8
select * from member where id not in (2,4,6,8);
select * from member where id between 3 and 5;
select * from member where id=3 or id=5;
select * from member where id=7 and sex='girl';
# 8.0 模糊查询
# 1.查找手机号以136开头的记录
select * from member where phonenum like '136%';
# 2.查找手机号以3作为结尾的记录
select * from member where phonenum like '%3';
# 3.查询姓名中包含字母n的记录
select * from member where username like '%n%';
# 9.0 使用数据库的 news
use news;
select userid from news_users
where username = 'ntd2304' and password='e10adc3949ba59abbe56e057f20f883e';
select userid from news_users
where username = 'admin' and password='e10adc3949ba59abbe56e057f20f883e';
#select userid from news_users
#where username = '' or 1=1#' and password='e10adc3949ba59abbe56e057f20f883e'
use mysee;
-
select * from book;
-
select * from book where id in(2,4,6,8,10);
-
select * from book where id not in(2,4,6,8,10);
-
select * from book where price between 60 and 80;
-
select * from book where title like '%网络%';
-
select * from book where title like '%基础';
-
select * from book where title like '__基础';
#一 SQL 语句的函数使用
#1 返回字符串的长度
select length('风的方向是自己决定的');

# 2 返回字符串的'渗透'
select substr('hello渗透测试hello',2,8);

#3 LEFT(str, length):返回字符串 str 的左边 length 个字符。
select left('Hello 渗透测试',4);

#4 RIGHT(str, length):返回字符串 str 的右边 length 个字符。
select right('Hello 渗透测试',4);
# 5? CONCAT(str1, str2, ...):将多个字符串拼接成一个字符串。
select concat('Hello','See you','goodseeyou');

# 6? group_concat? 同一个分组的多个字符串连接成一个字符串(列变行,每个数据之间以逗号分割)
# 查询mysee 数据库中的book表中的所有图书名称
select title from mysee.book;
select group_concat(title) from mysee.book;

#7 返回字符串中第一个字符的ascii码值 a=>97? A=>65? 0=>48

select ascii ('A');
select ascii ('a');
select ascii ('0');
select ascii ('i');
select ord('Z');
select ord('z');
select ord('9');
# 8 字符的编码 十六进制

-
select hex('d');
-
select ord('d');
-
select hex('hello,世界');
-
select hex('hello,shijie');
# 10.0 系统信息函数
# 1. 获取mysql的版本
select version();

# 2. 获取当前数据库的名称
select database();

# 3.获取当前用户
select user();

# 4. 返回数据库路径
select @@datadir;

#11.0 高级语法
# 1. 条件函数
select if(10>5,'success','failed');

# 2. 休眠函数
# select sleep(3);
# 3. 随机数,生成0~1之间的随机数
selec

t rand();
# 4.利用mysql读取文件
select load_file('D:/phpStudy/WWW/news/include/database.inc.php');
