mysql_入门操作 一.开启数据库 二.数据库登录与登出 三.数据库操作 四.表操作 五.数据操作 六.聚合函数   七.索引  

  1. 开启:net start mysql80
  2. 关闭:net stop mysql80

二.数据库登录与登出

  1. 登录:Mysql -u root -p
  2. 退出:exit

三.数据库操作

  1. 增:create database ‘库’;
  2. 删:drop database ‘库’;
  3. 改:alter database ‘库’ charset ‘类型’;
  4. 查:show database;
  5. 入:use ‘库’;
  6. 退:begin;

四.表操作

  1. 增:create table ‘表’{id int,name char,age int};
  2. 删:drop table ‘表’;
  3. 改:alter table ‘表’ rename ‘新’;
  4. 查: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 ‘表’;

五.数据操作

  1. 删:delete from ‘表’ where age<16;
  2. 增:insert into ‘表’ values(1,”name”,18);
  3. 改:update ‘表’ set age=19 where age=18;
  4. 查:select * from ‘表’;

六.聚合函数

max()求最大值

min()求最小值

avg()求平均值

sum() 求和

count() 求总个数

 

七.索引

 

索引可以大大缩短数据搜索时间

增:create index id on 表名;
改:alter table 表名 add index_id index(id);
删:drop index id on 表名;