当前位置:网站首页>MySQL——数据库基础
MySQL——数据库基础
2022-07-30 11:01:00 【大本钟下送快递】
一,数据库的操作
1.显示当前数据库(show databases;)
SHOW DATABASES; / show databases;
首先要说明的是MySQL 大小写字母皆可

2.创建数据库(create database[if not exists] 数据库名;)
create database[if not exists] 数据库名;
(1)if not exists 的作用
if not exists 加不加都可,但若数据库名重复
不加 if not exists ——报错

加 if not exists 后——警告

(2)使用的字符集——utf8mb4
系统使用默认字符集:utf8,校验规则是:utf8_ general_ ci,但是MySQL的utf8编码不是真正的utf8,没有包含某些复杂的中文字符。MySQL真正的使用的是utf8mb4
可用创建方式:
create database if not exists 数据库名 character set utf8;
后续可以插入中文

3.使用数据库(use 数据库名;)
use 数据库名;
4.删除数据库(drop database [if exists] 数据库名;)
drop database [if exists] 数据库名字;
数据库删除以后,内部看不到对应的数据库,里边的表和数据全部被删除,一不小心,损失百万
二,常用数据类型——对应java类型
1.数值类型
1.bit(M)——boolean M指定位数,默认为1字节 ,M范围1~64,存储数值范围0~2^M-1
2.tinyint——byte 1字节
3.smallint——short 2字节
4.int——integer 4字节
5.bigint——long 8字节
6.float(M,D)——float 4字节 M指定长度,D指定小数位数,会发生精确丢失
7.double(M,D)——double 8字节
8.decimal(M,D)——bigdecimal M/D最大值+2字节 M指定长度,D指定小数位数,精确数值
9.numeric(M,D)——bigdecimal M/D最大值+2字节 M指定长度,D指定小数位数,精确数值
注意:
①数值类型可以指定为无符号(unsigned),表示不取负数,但不推荐这样使用
②对于放不下的数据,一开始就使用bigint类型
2.字符串类型
1.varchar——string 可变长度字符串
2.text——String 长文本文件
3.mediumtext——string 中等长度文本数据
4.blob——byte 二进制形式的长文本数据
对于一个不清楚类型的文件,可以尝试使用记事本来打开,若出现内容可以看懂,有规律,即是文本文件,反之,为二进制文件
3.日期类型
1.datetime——java.util.Date
2.timestamp——java.util.Date
三,表的操作
操作表之前,需要先使用该数据库
use 数据名;
1.创建表(create table 表名(列名 类型 ,列名 类型...);)
create table 表名(列名 类型 comment '注释' ,列名 类型/*注释*/, ...);
注释: comment' 注释', /* 注释*/
注意,1.如果列较多,建议分行来写
2.可以先在其他编辑器编辑,再粘贴
create table 表名 (
id int,
name varchar(20) comment '姓名',
password varchar(50) comment '密码',
age int ,
sex varchar(1),
birthday timestamp,
amout decimal(13,2),
resume text
);
注意:
1.varchar后面的数字不能省略
2.末尾的 ); 单独占最后一行

2.查看表
(1).查看数据库有哪些表(show tables;)
show tables;

(2).查看表中的结构(desc 表名;)
desc 表名; (desc "描述")

解释:
1.11是描述的打印格式
2.Field字段
3.20是最多存20个字符
3.删除表(drop table[if not exists] 表名;)
drop table[if not exists] 表名;
四,数据库的增删改查(CRUD)
1.增
列名和相匹配
insert into 表名 values();
边栏推荐
- Detailed explanation of @RequestBody and @ResponseBody
- 360 released a future-oriented EDR to protect the security of government and enterprise user terminals in an all-round way
- 单片机开发之ADC0808/9信号采集
- Log4j additivity属性简介说明
- mysql与redis 区别
- 分布式限流 redission RRateLimiter 的使用及原理
- oracle export dmp file type as "crash dump file"
- 湖仓一体电商项目(一):项目背景和架构介绍
- Voltage relay h2d SRMUVS - 100 vac - 2
- async.js入门
猜你喜欢
随机推荐
图像去噪——Neighbor2Neighbor: Self-Supervised Denoising from Single Noisy Images
SQL language and paging rownum analysis in Oracle
深入浅出零钱兑换问题——背包问题的套壳
Neural Network Study Notes 4 - Autoencoder (including sparse, stacked) (updated)
UE5 GAS 学习笔记 后记0
360 released a future-oriented EDR to protect the security of government and enterprise user terminals in an all-round way
高能产出!腾讯内部的MyCat中间件手册,理论实操齐下
Scrapy crawler website image crawling
高手云集、丰富活动,斩获佳绩,超过2万名开发者参与的AI社团邀你加入!
Meikle Studio-Look at Hongmeng Device Development Practical Notes 7-Network Application Development
Oracle中SQL语言和分页rownum分析
Linux内核设计与实现(十)| 页高速缓存和页回写
The battle-hardened programmer was also deceived by a fake programmer from a certain fish. The trust between programmers should be the highest, and he alone destroyed this sense of trust
《跟唐老师学习云网络》 - 问题定位 - 主机通但容器不通
【Flume】batchSize和transactionCapacity区别
[Qualcomm][Network] 网络拨号失败和netmgrd服务分析
加密和安全
Basemap and Seaborn
系统设计精选 | 基于FPGA的CAN总线控制器的设计(附代码)
向上管理读书笔记








