【MySQL】-- 数据库约束

文章目录

  • 1. 什么是数据库约束
  • 2. 约束类型
  • 3. NOT NULL 非空约束
  • 4. DEFALUT 默认值约束
  • 5. UNIQUE 唯一约束
  • 6. PRIMARY KEY 主键约束
    • 6.1 自增主键
    • 6.1 一个自增主键包含多个列
  • 7. FOREIGN KEY 外键约束
  • 8. CHECK 约束

1. 什么是数据库约束

数据库约束是指对数据库表中的数据所施加的规则或条件,用于确保数据的准确性和可靠性。这些约束可以是基于数据类型、值范围、唯一性、非空等规则,以确保数据的正确性和相容性。

数据库约束时关系型数据库的一个重要功能,主要的作用是保证数据的有效性,也可以理解为数据的正确性(数据本身是否正确,关联关系是否正确)。

人工检查数据的完整性工作量非常大,在数据库中定义一些约束,那么数据在写入数据库的时候,就会帮我们做一些校验。约束一般是在指定的列上创建的。

2. 约束类型

类型说明
NOTNULL⾮空约束指定非空约束的列不能存储NULL值
DEFALUT默认约束当没有给列赋值时使用的默认值
UNIQUE唯一约束指定唯一约束的列每行数据必须有唯一的值
PRIMARYKEY主键约束NOTNULL和UNIQUE的结合,可以指定一个列或多个列,有助于防止数据重复和提高数据的查询性能
FOREIGNKEY外键约束外键约束是一种关系约束,用于定义两个表之间的关联关系,可以确保数据的完整性和一致性
CHECK约束用于限制列或数据在数据库表中的值,确保数据的准确性和可靠性

前四个比较常用。

3. NOT NULL 非空约束

定义表时某列不允许为null时,可以为列添加非空约束。

  • 比如创建一个学生表,学生名为null时,这条记录是不完整的
-- 创建表
mysql> drop table if exists student;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> create table student(-> id bigint,-> name varchar(20)-> );
Query OK, 0 rows affected (0.03 sec)
-- 插入数据
mysql> insert into student values (1, null);
Query OK, 1 row affected (0.01 sec)
//查询
mysql> select * from student;
+------+------+
| id   | name |
+------+------+
|    1 | NULL |
+------+------+
1 row in set (0.03 sec)

姓名为null,没有意义。

  • 此时需要约束学生名的列不能为null
-- 创建表
mysql> drop table if exists student;
Query OK, 0 rows affected (0.05 sec)
-- 为name列添加非空约束
mysql> create table student(-> id bigint,-> name varchar(20) not null-> );
Query OK, 0 rows affected (0.05 sec)
-- 插入name为null的数据,会报错
mysql> insert into student (id, name) values (1, null);
ERROR 1048 (23000): Column 'name' cannot be null
-- 插入非空数据,可以正常插入
mysql> insert into student (id, name) values (1, '张三');
Query OK, 1 row affected (0.03 sec)
-- 查询数据
mysql> select * from student;
+------+------+
| id   | name |
+------+------+
|    1 | 张三 |
+------+------+
1 row in set (0.00 sec)
  • 查看表结构
mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | bigint      | YES  |     | NULL    |       |
| name  | varchar(20) | NO   |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

可以看到student表中的Null列对应的name那一行显示为NO,就表示name不能为空。

4. DEFALUT 默认值约束

DEFALUT约束用于向列中插入默认值,如果没有为列设置值,那么会将默认值设置到该列

  • 创建学生表,新增年龄列,并为其设置默认值18
mysql> drop table if exists student;
Query OK, 0 rows affected (0.01 sec)-- 创建表
mysql> create table student(-> id bigint primary key auto_increment,-> name varchar(20) not null,-> age int default 18-> );
Query OK, 0 rows affected (0.02 sec)-- 查看表结构
mysql> desc student;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | bigint      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | NO   |     | NULL    |                |
| age   | int         | YES  |     | 18      |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

没有指定值的就用默认值填充

-- 添加数据
mysql> insert into student (name) values ('张三'), ('王五');
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0mysql> select * from student;
+----+------+------+
| id | name | age  |
+----+------+------+
|  1 | 张三 |   18 |
|  2 | 王五 |   18 |
+----+------+------+
2 rows in set (0.01 sec)

有指定值就用指定值填充

mysql> insert into student (name, age) values ('赵六', 20);
Query OK, 1 row affected (0.00 sec)mysql> select * from student;
+----+------+------+
| id | name | age  |
+----+------+------+
|  1 | 张三 |   18 |
|  2 | 王五 |   18 |
|  3 | 赵六 |   20 |
+----+------+------+
3 rows in set (0.00 sec)

5. UNIQUE 唯一约束

指定了唯一约束的列,该列的值在所有记录中不能重复,比如一个人的身份证号,学生的学号等。

  • 重构学生表,新增学号列
mysql> drop table if exists student;
Query OK, 0 rows affected (0.05 sec)mysql> create table student(-> id bigint,-> name varchar(20),-> sno varchar(10)-> );
Query OK, 0 rows affected (0.06 sec)
  • ** 不设置唯一约束时,学号可以重复**
mysql> insert into student (id, name, sno) values (1, '张三', '123456789');
Query OK, 1 row affected (0.00 sec)mysql> insert into student (id, name, sno) values (1, '张三', '123456789');
Query OK, 1 row affected (0.00 sec)mysql> select * from student;
+------+------+-----------+
| id   | name | sno       |
+------+------+-----------+
|    1 | 张三 | 123456789 |
|    1 | 张三 | 123456789 |
+------+------+-----------+
2 rows in set (0.00 sec)
  • ** 重构学生表,为学号列设置唯一约束**
mysql> drop table if exists student;
Query OK, 0 rows affected (0.02 sec)mysql> create table student(-> id bigint,-> name varchar(20),-> sno varchar(10) UNIQUE-> );
Query OK, 0 rows affected (0.09 sec)mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | bigint      | YES  |     | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
| sno   | varchar(10) | YES  | UNI | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
  • 插入重复的学号时会报错,这就是唯一约束在生效
mysql> insert into student (id, name, sno) values (1, '张三', '123456789');
Query OK, 1 row affected (0.03 sec)mysql> insert into student (id, name, sno) values (1, '张三', '123456789');
ERROR 1062 (23000): Duplicate entry '123456789' for key 'student.sno'
  • 加入唯一约束的列可以写入null值,且可以写入多个null值
mysql> insert into student (id, name, sno) values (1, '张三', null);
Query OK, 1 row affected (0.03 sec)mysql> insert into student (id, name, sno) values (1, '张三', null);
Query OK, 1 row affected (0.03 sec)mysql> insert into student (id, name, sno) values (1, '张三', null);
Query OK, 1 row affected (0.03 sec)mysql> select * from student;
+------+------+-----------+
| id   | name | sno       |
+------+------+-----------+
|    1 | 张三 | 123456789 |
|    1 | 张三 | NULL      |
|    1 | 张三 | NULL      |
|    1 | 张三 | NULL      |
+------+------+-----------+
4 rows in set (0.00 sec)

6. PRIMARY KEY 主键约束

  • 主键约束唯一 标识数据库表中的每条记录(数据库管理数据时,使用主键列作为数据行的“身份证编号”)。
  • 主键必须包含唯一的值,且不能包含null值(非空约束 + 唯一约束)。
  • 每个表只能有一个主键,可以由单个列或多个列组成(主键由多个列组成的是复合主键)。
  • 通常每张表都只当一个主键,主键列建议使用bigint类型(范围足够大,不会溢出)。
  • 重构学生表,为ID列添加非空和唯一约束
mysql> drop table if exists student;
Query OK, 0 rows affected (0.01 sec)mysql> create table student(-> id bigint not null unique,-> name varchar(20) not null-> );
Query OK, 0 rows affected (0.02 sec)mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | bigint      | NO   | PRI | NULL    |       |
| name  | varchar(20) | NO   |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

在id列上加了非空约束和唯一约束,在表结构上的key那一列显示PRI。

mysql> drop table if exists student;
Query OK, 0 rows affected (0.01 sec)mysql> create table student(-> id bigint primary key,-> name varchar(20) not null-> );
Query OK, 0 rows affected (0.02 sec)mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | bigint      | NO   | PRI | NULL    |       |
| name  | varchar(20) | NO   |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

为id列加上主键约束,可以看到在表结构的key那一列显示PRI

非空约束 + 唯一约束 = 主键约束

6.1 自增主键

  • 把表中的ID字段设置成自增主键
mysql> drop table if exists student;
Query OK, 0 rows affected (0.02 sec)mysql> create table student(-> id bigint primary key auto_increment,-> name varchar(20) not null-> );
Query OK, 0 rows affected (0.04 sec)mysql> desc student;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | bigint      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | NO   |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
  • auto_increment是自增的关键字,一个表中只能由一个列是自增列。
  • 可以在表结构的Extra列上看到auto_increment
  • 可以手动指定主键列的值,但是要保证不重复
mysql> insert into student (id, name) values (1, '张三');
Query OK, 1 row affected (0.01 sec)mysql> insert into student (id, name) values (1, '李四');
ERROR 1062 (23000): Duplicate entry '1' for key 'student.PRIMARY'
mysql> insert into student (id, name) values (2, '李四');
Query OK, 1 row affected (0.03 sec)
  • 主键列在手动设置时,如果设置为null,则会使用自增
mysql> insert into student (id, name) values (null, '王五');
Query OK, 1 row affected (0.01 sec)mysql> select * from student;
+----+------+
| id | name |
+----+------+
|  1 | 张三 |
|  2 | 李四 |
|  3 | 王五 |
+----+------+
3 rows in set (0.01 sec)
  • 插入除了主键之外的所有非空列(推荐使用这种方法插入数据)
mysql> insert into student (name) values ('赵六');
Query OK, 1 row affected (0.01 sec)mysql> select * from student;
+----+------+
| id | name |
+----+------+
|  1 | 张三 |
|  2 | 李四 |
|  3 | 王五 |
|  4 | 赵六 |
+----+------+
4 rows in set (0.01 sec)
  • 自定义的主键值,只要满足非空和唯一即可,不需要严格按照数字递增
mysql> insert into student (id, name) values (100, '哈哈');
Query OK, 1 row affected (0.01 sec)mysql> select * from student;
+-----+------+
| id  | name |
+-----+------+
|   1 | 张三 |
|   2 | 李四 |
|   3 | 王五 |
|   4 | 赵六 |
| 100 | 哈哈 |
+-----+------+
5 rows in set (0.00 sec)mysql> insert into student (id, name) values (99, '哈哈');
Query OK, 1 row affected (0.01 sec)mysql> select * from student;
+-----+------+
| id  | name |
+-----+------+
|   1 | 张三 |
|   2 | 李四 |
|   3 | 王五 |
|   4 | 赵六 |
|  99 | 哈哈 |
| 100 | 哈哈 |
+-----+------+
6 rows in set (0.00 sec)mysql> insert into student (name) values ('哈哈2');
Query OK, 1 row affected (0.01 sec)mysql> select * from student;
+-----+-------+
| id  | name  |
+-----+-------+
|   1 | 张三  |
|   2 | 李四  |
|   3 | 王五  |
|   4 | 赵六  |
|  99 | 哈哈  |
| 100 | 哈哈  |
| 101 | 哈哈2 |
+-----+-------+
7 rows in set (0.00 sec)

6.1 一个自增主键包含多个列

mysql> drop table if exists student;
Query OK, 0 rows affected (0.01 sec)mysql> create table student(-> id bigint,-> name varchar(20),-> primary key (id, name)-> );
Query OK, 0 rows affected (0.02 sec)mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | bigint      | NO   | PRI | NULL    |       |
| name  | varchar(20) | NO   | PRI | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
  • 如果定义的主键包含多个列,那么表示的是多个列的值用-连起来的值,不能重复
mysql> insert into student (id, name) values (1, '张三');
Query OK, 1 row affected (0.01 sec)mysql> insert into student (id, name) values (2, '张三');
Query OK, 1 row affected (0.00 sec)mysql> select * from student;
+----+------+
| id | name |
+----+------+
|  1 | 张三 |
|  2 | 张三 |
+----+------+
2 rows in set (0.00 sec)mysql> insert into student (id, name) values (2, '张三');
ERROR 1062 (23000): Duplicate entry '2-张三' for key 'student.PRIMARY'

7. FOREIGN KEY 外键约束

  • 外键约束用于定义主表和从表之间的关系。
  • 外键约束定义在从表的列上,主表关联的列必须是主键或唯一约束。
  • 当定义外键后,要求从表中的外键列数据必须在主表的主键或唯一列存在或为null.

外键约束也是对数据的一个校验过程,从表中使用主表中的某个值,这个值必须在主表中存在。

在这里插入图片描述

语法

foreign key (class_id) references class(id)
  • 创建班级表(主表),并初始化数据
mysql> drop table if exists class;
Query OK, 0 rows affected, 1 warning (0.04 sec)mysql> create table class(-> id bigint primary key auto_increment,-> name varchar(20) not null-> );
Query OK, 0 rows affected (0.05 sec)mysql> insert into class (name) values ('java01'), ('java02'), ('java03'), ('C++01'), ('C++02');
Query OK, 5 rows affected (0.03 sec)
Records: 5  Duplicates: 0  Warnings: 0mysql> select * from class;
+----+--------+
| id | name   |
+----+--------+
|  1 | java01 |
|  2 | java02 |
|  3 | java03 |
|  4 | C++01  |
|  5 | C++02  |
+----+--------+
5 rows in set (0.02 sec
  • 创建学生表,加入外键约束
mysql> drop table if exists student;
Query OK, 0 rows affected (0.03 sec)mysql> create table student(-> id bigint primary key auto_increment,-> name varchar(20) not null,-> sno varchar(20) unique,-> class_id bigint not null,-> foreign key (class_id) references class (id)-> );
Query OK, 0 rows affected (0.04 sec)mysql> desc student;
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| id       | bigint      | NO   | PRI | NULL    | auto_increment |
| name     | varchar(20) | NO   |     | NULL    |                |
| sno      | varchar(20) | YES  | UNI | NULL    |                |
| class_id | bigint      | NO   | MUL | NULL    |                |
+----------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

在这里插入图片描述

  • 插入一个班级编号在主表中不存在的一组数据
mysql> insert into student(name, sno, class_id) values ('qianqi', '1007', 6);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`java114`.`student`, CONSTRAINT `student_ibfk_1` FOREIGN KEY (`class_id`) REFERENCES `class` (`id`))
  • 删除主表中的数据
mysql> select * from student;
+----+------+-------+----------+
| id | name | sno   | class_id |
+----+------+-------+----------+
|  5 | 张三 | 10001 |        1 |
|  6 | 王五 | 10002 |        3 |
|  7 | 赵六 | 10003 |        5 |
+----+------+-------+----------+
3 rows in set (0.00 sec)mysql> select * from class;
+----+--------+
| id | name   |
+----+--------+
|  1 | java01 |
|  3 | java03 |
|  4 | C++01  |
|  5 | C++02  |
+----+--------+
4 rows in set (0.00 sec)mysql> delete from class where id = 3;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`java114`.`student`, CONSTRAINT `student_ibfk_1` FOREIGN KEY (`class_id`) REFERENCES `class` (`id`))

删除主表中的数据时,如果从表中有对主表的引用,则不允许删除主表的记录。

mysql> select * from student;
+----+------+-------+----------+
| id | name | sno   | class_id |
+----+------+-------+----------+
|  5 | 张三 | 10001 |        1 |
|  6 | 王五 | 10002 |        3 |
|  7 | 赵六 | 10003 |        5 |
+----+------+-------+----------+
3 rows in set (0.00 sec)mysql> select * from class;
+----+--------+
| id | name   |
+----+--------+
|  1 | java01 |
|  3 | java03 |
|  4 | C++01  |
|  5 | C++02  |
+----+--------+
4 rows in set (0.00 sec)mysql> delete from student where class_id = 3;
Query OK, 1 row affected (0.01 sec)mysql> select * from class;
+----+--------+
| id | name   |
+----+--------+
|  1 | java01 |
|  3 | java03 |
|  4 | C++01  |
|  5 | C++02  |
+----+--------+
4 rows in set (0.00 sec)mysql> select * from student;
+----+------+-------+----------+
| id | name | sno   | class_id |
+----+------+-------+----------+
|  5 | 张三 | 10001 |        1 |
|  7 | 赵六 | 10003 |        5 |
+----+------+-------+----------+
2 rows in set (0.00 sec)

如果要删除主表中的数据,必须先把从表中对主表的引用记录删除掉。

mysql> drop table class;
ERROR 3730 (HY000): Cannot drop table 'class' referenced by a foreign key constraint 'student_ibfk_1' on table 'student'.

删除主表时,必须先解除主外键关系或者先删除从表。

每当在有主外键约束的表中新增一条数据时,数据库都会为我们做校验,数据量非常大的时候,会严重影响数据库的效率,在真正的工作中,一般不会为表加主外键约束。

数据库的校验操作一般是在应用程序层面处理好,再把正确的数据直接写到数据库中。

8. CHECK 约束

可以应用于一个或多个列,用于限制列中可接收的数据值,从而保证数据的完整性和准确性。
在8.0.16开始全面支持CHECK约束,之前的版本会忽略CHECK约束。

但是在工作中,一般是在应用程序级别进行校验的。

  • 重构学生表,有以下要求,年龄不能小于16岁,性别只能是男或女
mysql> drop table if exists student;
Query OK, 0 rows affected (0.01 sec)mysql> create table student(-> id bigint primary key auto_increment,-> name varchar(20) not null,-> age int default 18,-> gender char(1),-> check(age >= 16),-> check(gender = '男' or gender = '女')-> );
Query OK, 0 rows affected (0.03 sec)mysql> desc student;
+--------+-------------+------+-----+---------+----------------+
| Field  | Type        | Null | Key | Default | Extra          |
+--------+-------------+------+-----+---------+----------------+
| id     | bigint      | NO   | PRI | NULL    | auto_increment |
| name   | varchar(20) | NO   |     | NULL    |                |
| age    | int         | YES  |     | 18      |                |
| gender | char(1)     | YES  |     | NULL    |                |
+--------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
  • 符合check条件的插入
mysql> insert into student (name, age, gender) values ('张三', 18, '男');
Query OK, 1 row affected (0.03 sec)mysql> select * from student;
+----+------+------+--------+
| id | name | age  | gender |
+----+------+------+--------+
|  1 | 张三 |   18 ||
+----+------+------+--------+
1 row in set (0.00 sec)
  • 不符合check条件(age)的插入
mysql> insert into student (name, age, gender) values ('张三', 15, '男');
ERROR 3819 (HY000): Check constraint 'student_chk_1' is violated.
  • 不符合check条件(gender)的插入
insert into student (name, age, gender) values ('王五', 18, '好');
ERROR 3819 (HY000): Check constraint 'student_chk_2' is violated.
  • ** 都不符合**
mysql> insert into student (name, age, gender) values ('赵六', 8, '好');
ERROR 3819 (HY000): Check constraint 'student_chk_1' is violated.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/79742.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

鸿蒙NEXT开发动画案例2

1.创建空白项目 2.Page文件夹下面新建Spin.ets文件,代码如下: // 接口定义(必须放在使用前) /*** 关键帧动画整体配置参数*/ interface KeyframeAnimationConfig {iterations: number;delay: number; }/*** 单个关键帧动画项*/…

团队协作的润滑剂——GitHub与协作流程

各位代码界的社交恐惧症患者们,今天我们要聊的是如何假装自己很会团队协作——使用GitHub!这就像程序员版的"相亲平台",只不过在这里,你展示的不是自拍和收入,而是代码和commit记录(后者往往更令…

「Mac畅玩AIGC与多模态13」开发篇09 - 基于多插件协同开发智能体应用(天气+名言查询助手)

一、概述 本篇介绍如何在 macOS 环境下,同时接入多个自定义 OpenAPI 插件,实现智能体根据用户请求自动分析,调用天气查询或名言查询服务,完成多功能协同应用开发。 二、环境准备 1. 确认本地开发环境 macOS 系统Dify 平台已部…

react-12父子组件间的数据传递(子传父)(父传子)- props实现

1.子组件调用父组件的函数并传递数据(子传父) 1.1父组件 import React, { Component } from react; import ChildComponent from ./ChildComponent;class ParentComponent extends Component {constructor(props) {super(props);this.state {items: […

Spring Boot 单元测试使用教程(仅供参考)

单元测试是软件开发中至关重要的一环&#xff0c;Spring Boot 提供了强大的测试支持。以下是 Spring Boot 单元测试的详细教程。 1. 准备工作 1.1 添加测试依赖 在 pom.xml 中添加测试相关依赖&#xff1a; <dependency><groupId>org.springframework.boot</…

React Hooks速成

1、useReducer 适用情况为对一个状态多种复杂操作,通俗的讲就是比如对count这个变量加减乘除的各种情况 改造前 import { useState } from "react";function App() {//计数器const [count, setCount] useState(0);const handleIncrement () > {setCount(coun…

k8s node 内存碎片化如何优化?

在 Kubernetes 集群中&#xff0c;内存碎片化&#xff08;Memory Fragmentation&#xff09;会导致系统无法分配连续的内存块&#xff0c;即使总内存充足&#xff0c;也可能触发 OOM&#xff08;Out of Memory&#xff09;或影响性能。以下是针对 k8s Node 内存碎片化的优化策略…

目标检测(Object Detection)研究方向常用数据集简单介绍

目录 一、目标检测研究方向简介 二、目标检测常用数据集详解 通用目标检测数据集 领域专用数据集 三、数据集选择建议 一、目标检测研究方向简介 目标检测是计算机视觉的核心任务之一&#xff0c;旨在从图像或视频中定位并识别出所有感兴趣的物体&#xff0c;输出其类别和…

即开即用,封装 Flask 项目为 exe 文件实操步骤

见字如面&#xff0c;朋友们&#xff01; 嗨&#xff0c;这里是 AIGC 创意人_竹相左边&#xff01; 正如你们所知&#xff0c;我正在通过 AI 自学软硬件工程师&#xff0c;目标是手搓一台可回收火箭玩具&#xff01; 最近&#xff0c;我被《流浪地球 2》中马兆的那句“没有硬…

uniapp开发微信小程序时如何进行分包(新手图文)

我们在进行uniapp微信小程序开发的时候&#xff0c;每次上传都提示包太大&#xff0c;主包大小不能超过 2M&#xff0c; 这就很头疼&#xff0c;这个时候&#xff0c;唯一的解决方案就是分包了&#xff0c;那如何进行分包呢&#xff1f; 分包步骤如下&#xff1a; 一、配置man…

基于C++的IOT网关和平台2:github项目ctGateway技术说明书

初级代码游戏的专栏介绍与文章目录-CSDN博客 我的github:codetoys,所有代码都将会位于ctfc库中。已经放入库中我会指出在库中的位置。 这些代码大部分以Linux为目标但部分代码是纯C++的,可以在任何平台上使用。 源码指引:github源码指引_初级代码游戏的博客-CSDN博客 系…

从巴别塔到通天塔:Manus AI 如何重构多语言手写识别的智能版图

一、引言&#xff1a;当人类手写遇上 AI “巴别塔” 在幼发拉底河畔的古老传说中&#xff0c;巴别塔的崩塌象征着人类语言互通的终结。而在数字时代&#xff0c;全球 7000 余种语言的手写文字&#xff0c;正成为横亘在人机交互之间的新 “巴别塔”—— 阿拉伯文的连笔天书、中…

n8n 快速入门2:构建自动化工作流

n8n 快速入门2:构建自动化工作流 什么是n8n?项目目标准备工作步骤一:创建新工作流步骤二:添加触发节点步骤三:配置NASA节点与凭证1. 添加NASA节点2. 设置NASA API凭证3. 使用表达式设置时间范围步骤四:添加If条件节点1. 创建条件分支2. 测试条件逻辑步骤五:配置输出节点…

从实列中学习linux shell10 : 如何根据服务器的内存,cpu 以及 ssd硬盘 来确定mysql 的最大并发数

以下是根据服务器硬件资源智能推荐MySQL最大并发连接数 包含详细的计算逻辑和实时资源检测&#xff1a; 且记&#xff1a;该脚本要放在 安装mysql的服务器上 运行 第一步&#xff1a;实现脚本 #!/bin/bash# 计算MySQL最大连接数推荐值 # 公式说明&#xff1a;取CPU计算值与内…

数据结构--AVL树

目录 前言 AVL树的特点 AVL树的插入 节点的定义 情况分析 AVL树的旋转 右单旋 左单旋 左右双旋 右左双旋 ​编辑总结 验证AVL树 前言 二叉搜索树可以帮助我们以极高的效率查找(理想情况下是logn)&#xff0c;但是当在极端情况下&#xff0c;比如当树中的节点值是有…

泰迪杯特等奖案例学习资料:基于多模态融合与边缘计算的智能温室环境调控系统

(第十二届泰迪杯数据挖掘挑战赛特等奖案例解析) 一、案例背景与核心挑战 1.1 应用场景与行业痛点 在现代设施农业中,温室环境调控直接影响作物产量与品质。传统温室管理存在以下问题: 环境参数耦合性高:温度、湿度、光照、CO₂浓度等参数相互影响,人工调控易顾此失彼。…

动手学深度学习12.1. 编译器和解释器-笔记练习(PyTorch)

以下内容为结合李沐老师的课程和教材补充的学习笔记&#xff0c;以及对课后练习的一些思考&#xff0c;自留回顾&#xff0c;也供同学之人交流参考。 本节课程地址&#xff1a;无 本节教材地址&#xff1a;12.1. 编译器和解释器 — 动手学深度学习 2.0.0 documentation 本节…

[java八股文][Java并发编程面试篇]并发安全

juc包下你常用的类&#xff1f; 线程池相关&#xff1a; ThreadPoolExecutor&#xff1a;最核心的线程池类&#xff0c;用于创建和管理线程池。通过它可以灵活地配置线程池的参数&#xff0c;如核心线程数、最大线程数、任务队列等&#xff0c;以满足不同的并发处理需求。Exe…

VMware搭建ubuntu保姆级教程

目录 VMware Ubuntu 虚拟机配置指南 创建虚拟机 下载 Ubuntu ISO 新建虚拟机 网络配置&#xff08;双网卡模式&#xff09; 共享文件夹设置 SSH 远程访问配置 VMware Ubuntu 虚拟机配置指南 创建虚拟机 下载 Ubuntu ISO 【可添加我获取】 官网&#xff1a;Get Ubunt…

冯诺依曼结构与哈佛架构深度解析

一、冯诺依曼结构&#xff08;Von Neumann Architecture&#xff09; 1.1 核心定义 由约翰冯诺依曼提出&#xff0c;程序指令与数据共享同一存储空间和总线&#xff0c;通过分时复用实现存取。 存储器总带宽 指令带宽 数据带宽 即&#xff1a;B_mem f_clk W_data f_…