一.MySQL概述
1.数据库概念
(1). 数据库:
DataBase(DB),是存储和管理数据的仓库。
(2). 数据库管理系统:
DataBase Management System(DBMS),操纵和管理数据库的大型软件。
(3). SQL:
Structured Query Language,操作关系型数据库的编程语言,定义了一套操作关系型数据库统一标准。
2.MySQL数据模型![](https://img-blog.csdnimg.cn/direct/093360f39bd3450d9c0aa9546b48fb04.png)
3.SQL简介![](https://img-blog.csdnimg.cn/direct/9cf4e7472ed4488dadf482ff145aa589.png)
![](https://img-blog.csdnimg.cn/direct/bf305811495241c490f095723379e02d.png)
![](https://img-blog.csdnimg.cn/direct/e0cdc308a58f4babae6326e299618f71.png)
二.数据库设计-DDL
1. 数据库![](https://img-blog.csdnimg.cn/direct/a53ecef2895c465d8d68a06f7dc96632.png)
2. MySQL客户端工具-图形化工具![](https://img-blog.csdnimg.cn/direct/5724051e65a44807b74fd76bd228934b.png)
![](https://img-blog.csdnimg.cn/direct/ee95c969ccd2429fb3f5716bc80a23af.png)
3. 表(创建、查询、修改、删除)![](https://img-blog.csdnimg.cn/direct/469366fb5a054dd1af7bc1dcaf4da786.png)
![](https://img-blog.csdnimg.cn/direct/150f7b9e64a046f991372b800e96a1cd.png)
-- DDL : 表结构
-- 创建 : 基本语法
create table tb_user
(
id int comment 'ID, 唯一标识',
username varchar(20) comment '用户名',
name varchar(10) comment '姓名',
age int comment '年龄',
gender char(1) comment '性别'
) comment '用户表';
-- 创建 : 基本语法(约束)
create table tb_user
(
id int primary key auto_increment comment 'ID, 唯一标识',
username varchar(20) not null unique comment '用户名',
name varchar(10) not null comment '姓名',
age int comment '年龄',
gender char(1) default '男' comment '性别'
) comment '用户表';
4. DDL (表操作)
MySQL中的数据类型有很多,主要分为三类:数值类型、字符串类型、日期时间类型。
参照《MySQL数据类型》
(1) 数据类型--->数值类型
(2) 数据类型--->字符串类型
(3) 数据类型--->日期时间类型
(4) 表操作总结
- 数据库 - 创建、查询、使用、删除.
- 表结构 - 创建(语法、约束、数据类型、设计)、查询、修改、删除.
三.数据库操作-DML
1. DML (INSERT)
2. DML (UPDATE)
-- DML : 更新数据 - update
-- 1. 将tb_emp 表的ID为1员工 姓名name字段更新为 '张三'
update tb_emp set name = '张三',update_time = now() where id = 1;
-- 2. 将 tb_emp 表的所有员工的入职日期更新为 '2010-01-01', 更新所有则没有where条件
update tb_emp set entrydate = '2010-01-01', update_time = now();
3. DML (DELETE)![](https://img-blog.csdnimg.cn/direct/a3883a400e7542a48dc7726aabcc5867.png)
-- DML : 删除数据 - delete
-- 1. 删除 tb_emp 表中 ID为1的员工
delete from tb_emp where id = 1;
-- 2. 删除 tb_emp 表中的所有员工
delete from tb_emp;