当前位置:网站首页>MySQL数据库基础
MySQL数据库基础
2022-06-10 19:13:00 【如风暖阳】

️前言️
文章主要介绍MySQL数据库中一些常见的操作,为专栏文章,系列介绍
博客主页:【如风暖阳】
精品Java专栏【JavaSE】、【Java数据结构】、【备战蓝桥】、【JavaEE初阶】、【MySQL】、
【数据结构】
欢迎点赞收藏留言评论私信必回哟本文由 【如风暖阳】 原创,首发于 CSDN
博主将持续更新学习记录收获,友友们有任何问题可以在评论区留言
博客中涉及源码及博主日常练习代码均已上传码云(gitee)
内容导读
MySQL数据库基础
1.数据库的操作
1.1 显示当前数据库
show databases;
1.2 创建数据库
create database [if not exists] 数据库名;
- []为可选项
1.3 使用数据库
use 数据库名;
1.4 删除数据库
drop database [if exists]数据库名;
- []为可选项
这项操作是非常危险的操作(从删库到跑路),一旦删除,数据极有可能就无法恢复了
2.常用数据类型
2.1 数值类型
| 数据类型 | 大小 | 说明 | 对应Java类型 |
|---|---|---|---|
| TINYINT | 1字节 | byte | |
| SAMLLINT | 2字节 | short | |
| int | 4字节 | Integer | |
| BIGINT | 8字节 | long | |
| FLOAT(M,D) | 4字节 | 单精度,M指定长度(有效数字个数),D指定小数位数。会发生精度丢失 | Float |
| DOUBLE(M,D) | 8字节 | Double | |
| DECIMAL(M,D) | M/D最大值+2 | 双精度,M指定长度,D表示小数点位数。精确数值 | BigDecimal |
2.2 字符串类型
| 数据类型 | 大小 | 说明 | 对应Java类型 |
|---|---|---|---|
| varchar(size) | 0-65,535字节 | 可变长度字符串 | String |
| text | 0-65,535字节 | 长文本数据 | String |
| blog | 0-65,635字节 | 二进制形式的长文本数据 | byte[] |
2.3 日期类型
| 数据类型 | 大小 | 说明 | 对应Java类型 |
|---|---|---|---|
| DATETIME | 8字节 | 范围从1000到9999年,不会进行时区的检索及转换。 | java.util.Datejava.sql.Timestamp |
| TIMESTAMP | 4字节 | 范围从1970到2038年,自动检索当前时区并进行转换 | java.util.Datejava.sql.Timestamp |
3.表的操作
需要操作数据库中的表时,需要先使用该数据库:
use 数据库名;
3.1 查看表结构
desc 表名;

3.2 创建表
语法:
create table table_name (
field1 datatype,
field2 datatype,
field3 datatype
);
可以使用comment增加字段说明
示例:
create table stu_test (
id int,
name varchar(20) comment '姓名',
password varchar(50) comment '密码',
age int,
sex varchar(1),
birthday timestamp,
amout decimal(13,2),
resume text
);
3.3 删除表
语法格式:
drop table [if exists] 表名;
4.内容重点总结
- 操作数据库:
-- 显示
show databases;
-- 创建
create database xxx;
-- 使用
use xxx;
-- 删除
drop database xxx;
- 常用数据类型:
INT:整型
DECIMAL(M, D):浮点数类型
VARCHAR(SIZE):字符串类型
TIMESTAMP:日期类型 - 操作表:
-- 查看
show 表;
-- 创建
create table 表名(
字段1 类型1,
字段2 类型2,
...
);
-- 删除
drop talbe 表名;
️最后的话️
总结不易,希望uu们不要吝啬你们的哟(^U^)ノ~YO!!如有问题,欢迎评论区批评指正
边栏推荐
- 历时2年442位作者132个机构!Google发布语言模型评价新基准BIG-bench,204个任务全面评价语言模型能力,附论文
- Logback exclude specified package / class / method log output
- 腾讯Libco协程开源库 源码分析(三)---- 探索协程切换流程 汇编寄存器保存 高效保存协程环境
- Office technical lecture: punctuation - Chinese - Daquan
- mixin-- 混入
- 软件定义边界(SDP)
- 最近的工作
- 详细解读TPH-YOLOv5 | 让目标检测任务中的小目标无处遁形
- MBA-day21 线性规划问题
- When the college entrance examination is opened, VR panorama can see the test site in this way
猜你喜欢

PDU会话流程

How to query the database table storage corresponding to a field on the sapgui screen

Rotated Sorted Array旋转排序数组相关题

Zabbix_原理架构-安装部署-自定义监控

2022.05.23 (lc_300_longest increment subsequence)

KP522201A采用 SOT23-6 封装的 4.5V 至 17V 输入、2A 输出、600kHz 同步降压转换器

Summary of "performance test" of special test
![[advanced C language] data storage [Part 2] [ten thousand words summary]](/img/b5/4e346cb971b0574faf0164d3dcd9c8.png)
[advanced C language] data storage [Part 2] [ten thousand words summary]

Trilogy to solve the problem of playing chess first and then

Source code analysis of Tencent libco collaboration open source library (III) -- Exploring collaboration switching process assembly register saving and efficient collaboration environment
随机推荐
2022.05.29 (lc_6079_price reduction)
Harbor镜像拉取凭证配置
TiDB - 快速入门,集群搭建
2022.05.23 (lc_300_longest increment subsequence)
After the college entrance examination, VR panoramic tour will show you the beautiful scenery of the scenic spot
FS2117升压IC输出5V2.4A同步整流
Complete knapsack problem and optimization tips
mixin-- 混入
Detailed interpretation of tph-yolov5 | making small targets in target detection tasks invisible
仅需三步学会使用低代码ThingJS与森数据DIX数据对接
2022.05.26 (lc_1143_longest common subsequence)
Basic instructions for ads and AXD
在VR全景中如何添加聚合热点?内容模块如何添加?
Zabbix_ Monitoring ssh/crond Service - wechat alarm
大厂测试员年薪30万到月薪8K,吐槽工资太低,反被网友群嘲?
站在今天这样一个时间节点上,或许对产业互联网有一个更加明晰的认识
Recent work
Dock/rancher2 deploy redis:5.0.9
基于改进SEIR模型分析上海疫情
Analyse du code source de Tencent libco CO CO - Process open source library