数据库连接池的工作机制:
服务器启动时会建立一定数量的池连接,并一直维持不少于此数目的池连接。
客户端程序需要连接时,池驱动程序会返回一个未使用的池连接并将其标记为忙。
如果当前没有空闲连接,池驱动程序就新建一定数量的连接, 新建连接的数量有配置参数决定。
当使用的池连接调用完成后, 池驱动程序将此连接标记为空闲,其他调用就可以使用这个连接。
1. 数据库的基本概念:
数据库的英文单词:DataBase 简称DB ;数据库是用于存储和管理数据库的仓库;
数据库的特点: 方便持久存储数据, 方便存储和管理数据, 使用了统一的方式操作数据库;
2. 常见的数据库软件

3.MySQL的安装 配置和卸载

4. SQL概念 语法及分类

5.DDL 操作数据库/表(创建 查询 修改 删除)
5-a 操作数据库





6. DML增删改表中的数据

eg

7. DQL
7-a : 查询表中的记录











7-bDQL查询语句

b-1 排序


:mysql中常用的数学函数

:mysql中常用的字符串函数
b-2 聚合函数
函数 sum()
1、没有group by,就只能有一条,sum得到的是总数
2、有group by,就分组了,sum得到的是分组后,每一个组的总数



b-3 分组


b-4分页查询

8. 约束
【primary key , unique , auto_increment, not null 】

-================================================================
not null

eg

unique


primary key


auto_increment

eg:

foreign key






9. 数据库的备份和还原

10. Mysql多表查询
【内链接查询,外链接查询 ,子查询 】
##创建部门表dept
create table dept(
id int primary key auto_increment,
name varchar(20)
);
insert into dept(name) values('开发部'),('市场部'),('财务部');
##创建部门表emp;
insert into emp(id,name,gender,salary,join_date,dept_id)
values (1,'王五','男','9800.21','2011-09-21',1);
insert into emp(id,name,gender,salary,join_date,dept_id)values
(null,'王六','女',8200,'2013-09-23',2),
(null,'赵四','女',7500,'2014-05-10',2),
(null,'张倩','女',6200,'2015-03-15',3);
create table emp(
id int primary key auto_increment,
name varchar(10),
gender char(1),
salary double,
join_date date,
dept_id int,
foreign key (dept_id) references dept(id) -- 外键
)
10-a 内链接查询
10-a-1 : 隐式 内链接查询

10-a-2 : 显示 内链接查询

10-b 外链接查询


10-c 子查询




联合查询

12.事务





13. mysql DCL

查询添加 删除 用户
##切换到mysql数据库
use mysql;
##查询user表
select*from user;
##创建用户
create user '用户名'@'主机名' identified by '密码';
create user 'tina'@'localhost' identified by 'lyn920921';
create user 'tina'@'%' identified by 'lyn920921';
##删除用户
drop user '用户名'@'主机名';
drop user 'tina'@'localhost';


14. mysql 常用的储存引擎

=======================================================================================
数据库的考点:多表联查,聚合函数和分组, 自查询
1. 简述数据库查询语句中,内连接inner join ,左连接 left join ,右连接 right join 的区别 ???
a)内连接 两表中数据对应存在
b) 左连接 左边表中的数据都会显示,如果右表中没有对应的数据就显示为空
c) 右连接 右边表中的数据都会显示,如果左表没对应数据,就显示为空

2.mysql行转列:
···
select ‘姓名’
min( case when '科目' = '语文' then '成绩' end ) '语文'
min( case when '科目' = '数学' then '成绩' end ) '数学'
from score
group by '姓名'
···
3. 经典的sql
1. 查询出A表中符合条件的数据 插入到B表中对应的字段中;
NSERT INTO student (`id`, `name`, `age`, `sex`, `addr`, `createTime`)
SELECT id, name, age, sex, addr,createTime FROM people
WHERE namein ('tina', 'lily') AND age= '1' and set= "1" and DATE_FORMAT(createTime ,'%Y%m%d')= DATE_FORMAT("20220101",'%Y%m%d') ;
SELECT 'addr' AS typeName,t1.addr as typeValue from (SELECT DISTINCT (addr ) FROM student ) t1
- 求两门以上(含2门)不及格的学生信息 及平均分
SELECT
sum(sc.scgrade<60) as cont, s.sname,avg(sc.scgrade)
FROM
t_course AS c,
t_sc AS sc,
t_student AS s
WHERE
c.cid = sc.cid AND s.sid = sc.sid
group by s.sname
having cont>=2;
- 求没有选修"孑孑"老师课程的所有学生的姓名
select s.sname from t_student as s where s.sid in (
select sc.sid
from t_course as c left join t_sc as sc
on c.cid=sc.cid where c.cteacher not like "孑孑%");
网友评论