mysql数据库基本操作及navicat安装包

1. 安装好mysql数据库

启动mysql数据库
在cmd命令窗口启动,使用管理员权限打开cmd命令窗口,启动

net start mysql

2. 使用navicat进行数据库的操作

navicat是数据库可视化管理工具,需要解码,可以去b站找,也可通过下方链接
链接:https://pan.baidu.com/s/1DtfqX-GwnZL-thH_wJJgrw?pwd=6666
提取码:6666
具体连接数据库方法这里就不赘述了,可以去看一下navicat基本操作方法。

3. mysql基本语法

3.1 创建数据库

创建名为Tests的数据库;

create database Tests;

在这里插入图片描述

3.2 查询数据库

查询本地中的所有数据库

show databases;

在这里插入图片描述

3.3 选择数据库

具体要操作哪个数据库要进行选择,例如要操作Tests数据库

use Tests;

在这里插入图片描述

3.4 查询数据库

由于我新建的数据库,没有表所以为空

show tables;

在这里插入图片描述

3.5 创建数据表

创建数据表成功,创建数据表基本语法
create table 名字(列的名称 类型)

create table student(id int,name char(10),age int,sex char(5));

在这里插入图片描述

3.6 查询表结构

查询表结构是在选择数据库的基础上去做的

desc student;

在这里插入图片描述

3.7数据表添加列

语法结构 alter table 表名 add 要添加的列名 类型;

alter table student add height int(10);

在这里插入图片描述

3.8 数据表删除列

语法结构 alter table 表名 drop 列名;

alter table student drop age;

在这里插入图片描述

3.9 数据列改名

语法结构 alter table 表名 change column 要改的列名 改的名字 类型;

alter table student change column height high int(3);

在这里插入图片描述

3.10 数据列修改数据类型

语法 alter table 表名 modify column 修改的数据列 类型;

alter table student modify column high char(10);

在这里插入图片描述

3.11 修改数据表名

alter table student rename student_table;

3.12 插入数据项

3.12.1数据表中文编码错误以及插入数据

有时添加中文到数据表中会有编码错误第一行就是为了解决编码错误问题

ALTER TABLE student_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE student_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
insert into student_table(id,name,sex,height) value (001,"张三","男",160);

在这里插入图片描述

3.13 删除数据项

选择某一个属性为标准进行删除,下列为删除high为140的一行数据

 delete from student where height=140;

3.14 更新数据项

对数据表中数据value数据进行重写

 update student set height=180;

在这里插入图片描述

3.15删除表

drop table student;

3.16 删除数据库

drop database Tests;

4. 逻辑运算符

1.between 最小值 and 最大值
语法:select * from 表名 where 列名 between 最小值 and 最大值;

select * FROM student_table where height BETWEEN 170 and 190;

在这里插入图片描述
作用和使用><是一样的

select * FROM student_table where height>=170 and height<=190;

在这里插入图片描述
2.null
语法:select * from 表名 where 列名 is null;(判断这一列有空值)

select * from student_table where height is null;

在这里插入图片描述
3. in (取值范围)
语法:select * from 表名 where 列名 in (值1,值2,…)

select * from student_table where height in (170,190);

在这里插入图片描述
4.like 好像
通配符: % 代表任意字符 _ 一个下划线代替一个字符
语法:select * from 表名 where 列名 like ‘通配符 特征 通配符’;

 select * from student_table where name like '张_';

在这里插入图片描述
5.as 为表名称或者列名称指定别名

select id as student_id from student_table where name like '张_';

在这里插入图片描述
6.union 合并两个或多个select语句结果集

 select id from student_table as st where st.name like '张_' union select name from student_table where height=190;

在这里插入图片描述

五,排序

关键词 order by
排序规则:升序排序 asc (默认可省略) 降序排序 desc
语法:
单列 select * from 表名 order by 列名 asc或者 desc;
多列 select * from 表名 order by 列名 asc或者 desc,列名2 asc或者desc,…;

 select * from student_table order by height asc,name desc;

在这里插入图片描述
四,去重
GROUP BY 和 DISTINCT 都是用于从数据库中选择唯一值的 SQL 子句

  select distinct height from student_table;

在这里插入图片描述

select height,count(*) from student_table group by height;

在这里插入图片描述
待续…

  • 28
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值