当前位置:网站首页>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!!如有问题,欢迎评论区批评指正
边栏推荐
- HW蓝队中级面试复盘
- The annual salary of testers in large factories ranges from 300000 to 8K a month. Roast complained that the salary was too low, but he was ridiculed by netizens?
- Spark ShuffleManager
- 刷脸认证如何实现人脸又快又准完成校验?
- 功耗开发经验分享:设计功耗大板
- Basic instructions for ads and AXD
- 一文详解EventMesh落地华为云的探索及实践
- Tencent libco collaboration open source library source code analysis full series summary blog
- 高通 QC2.0 快速充电智能识别IC FP6719
- Congratulations | Najie research group of Medical College revealed the function of junB in the process of differentiation of artificial blood progenitor cells in vitro through multi group analysis
猜你喜欢

详细解读TPH-YOLOv5 | 让目标检测任务中的小目标无处遁形

Rotated sorted array

Bit operation topic

One question to explain the past and present life of dynamic planning

8.4v双节锂电池专业充电ic(FS4062A)

批量检测不同url的指定端口(py脚本)

One article explains in detail the exploration and practice of eventmesh landing on Huawei cloud

2022.05.28 (lc_5_longest palindrome substring)
![[advanced C language] advanced pointer [Part 2]](/img/fe/44e7f7c39bd77239b9a70628768ecc.png)
[advanced C language] advanced pointer [Part 2]

Batch detection of specified ports of different URLs (py script)
随机推荐
First batch! Sinomenine has passed CWPP capability assessment and inspection of Xintong Institute
ZABBIX server trapper Remote Code Execution Vulnerability (cve-2017-2824)
MBA-day21 线性规划问题
Solving Bob's survival problem by trilogy routine
Harbor image pull voucher configuration
Office technical lecture: punctuation - Chinese - Daquan
【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结
Deep understanding of lightgbm
腾讯云数据库TDSQL-大咖论道 | 基础软件的过去、现在、未来
Change the root
用 Plotly 绘制了几张精湛的图表,美翻了!!
騰訊Libco協程開源庫 源碼分析(二)---- 柿子先從軟的捏 入手示例代碼 正式開始探究源碼
How to apply VR panorama in home decoration? Experience the real home decoration effect
Rmarkdown easily input mathematical formula
PDU会话流程
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
2022.05.25 (lc_718_longest repeating subarray)
FPGA状态机
Detailed interpretation of tph-yolov5 | making small targets in target detection tasks invisible
Batch detection of specified ports of different URLs (py script)