一.开启数据库
- 开启:net start mysql80
- 关闭:net stop mysql80
二.数据库登录与登出
- 登录:Mysql -u root -p
- 退出:exit
三.数据库操作
- 增:create database ‘库’;
- 删:drop database ‘库’;
- 改:alter database ‘库’ charset ‘类型’;
- 查:show database;
- 入:use ‘库’;
- 退:begin;
四.表操作
- 增:create table ‘表’{id int,name char,age int};
- 删:drop table ‘表’;
- 改:alter table ‘表’ rename ‘新’;
- 查:show tables;
1.1 增加一个相同成员类型的表:create table '新' like '旧';
3.1 成员增:alter table ‘表’ add ‘成员名’ ‘类型’;
3.2 成员删:alter table ‘表’ drop ‘成员名’;
3.3 成员改(类型):alter table ‘表’ modify ‘成员名’ ‘新类型’;
3.4 成员改(名+类型):alter table ‘表’ change ‘原名’ ‘新名’ ‘类型’;
4.1 查表类型:desc ‘表’;
五.数据操作
- 删:delete from ‘表’ where age<16;
- 增:insert into ‘表’ values(1,”name”,18);
- 改:update ‘表’ set age=19 where age=18;
- 查:select * from ‘表’;
六.聚合函数
max()求最大值
min()求最小值
avg()求平均值
sum() 求和
count() 求总个数
七.索引
索引可以大大缩短数据搜索时间
增:create index id on 表名;
改:alter table 表名 add index_id index(id);
删:drop index id on 表名;