当前位置:网站首页>Data type binary string type
Data type binary string type
2022-07-24 13:44:00 【Hua Weiyun】
9.4 Binary string type
MySQL The binary string type in mainly stores some binary data , For example, you can store pictures 、 Binary data such as audio and video , This section briefly introduces MySQL Supported binary string types .
9.4.1 Overview of binary string types
MySQL Binary string types supported in mainly include BIT、BINARY、VARBINARY、TINYBLOB、BLOB、MEDIUMBLOB and LONGBLOB type . The length and storage space of each type are shown in the table 9-10 Shown .
surface 9-10 Binary string type length and occupied space


The storage space occupied by each binary string type is also different .
9.4.2 BIT type
BIT Type in the , The minimum number of digits of each value is 1, The maximum value is 64, The default number of digits is 1.BIT Type stores binary values .
Create data table t20,t20 The data table contains a BIT Type field b.
mysql> CREATE TABLE t20 ( -> b BIT(5) -> );Query OK, 0 rows affected (0.02 sec)towards t20 Insert data into the table 2、8、16.
mysql> INSERT INTO t20 (b) VALUES (2), (8), (16);Query OK, 3 rows affected (0.00 sec)Records: 3 Duplicates: 0 Warnings: 0see t20 Table data .
mysql> SELECT * FROM t20;+------+| b |+------+| || || |+------+3 rows in set (0.00 sec)Use SELECT*FROM t20 The data queried by the statement cannot be viewed , This is because BIT Type stores binary data .
Use the following statement to query t20 Table data .
mysql> SELECT BIN(b+0) FROM t20;+----------+| BIN(b+0) |+----------+| 10 || 1000 || 10000 |+----------+3 rows in set (0.00 sec)It can be seen that , It has been found correctly 2、8、16 The binary value of . among , In the query statement b+0(b Represents the defined field name b) It means that the result of the stored binary value is converted into the value of the corresponding binary digit .BIN() Function converts a number to binary .
You can also use the following statement to query t20 Data stored in tables .
mysql> SELECT b+0 FROM t20; +------+| b+0 |+------+| 2 || 8 || 16 |+------+3 rows in set (0.00 sec)You can see , Use b+0 When querying data , The decimal value can be directly queried .
Be careful : In the BIT When inserting data into a field of type , Be sure to insert data in BIT Within the scope of type support .
9.4.3 BINARY And VARBINARY type
BINARY The type is a fixed length binary type , When the inserted data does not reach the specified length , Will be filled after the data “\0” character , To reach the specified length . meanwhile BINARY The storage space of the type field is also a fixed value .
VARBINARY The type is variable length binary type , The minimum length is 0, The maximum value is defined VARBINARY The length value specified when a field of type , Its storage space is the actual length of the data plus 1.
Create data table t21,t21 There is one in the table BINARY Type field b And one VARBINARY Type field vb.
mysql> CREATE TABLE t21 ( -> b BINARY(10), -> vb VARBINARY(10) -> );Query OK, 0 rows affected (0.02 sec)among ,b Fields and vb The length specified in the field is 10.
towards t21 Insert data into the table .
mysql> INSERT INTO t21 (b ,vb) VALUES (10, 10);Query OK, 1 row affected (0.01 sec)Inquire about t21 The length of the data in the table .
mysql> SELECT LENGTH(b), LENGTH(vb) FROM t21;+-----------+------------+| LENGTH(b) | LENGTH(vb) |+-----------+------------+| 10 | 2 |+-----------+------------+1 row in set (0.00 sec)You can see ,b The length of the field data is 10,vb The data length of the field is 2. explain BINARY The field length of type is a fixed value , The length of the field specified when defining the field , and VARBINARY The value of the field length of type is variable .
9.4.4 BLOB type
MySQL Medium BLOB Types include TINYBLOB、BLOB、MEDIUMBLOB and LONGBLOB 4 Types , Can store a large binary object , Such as the picture 、 Audio and video, etc .
It should be noted that , In practice , Often not in MySQL Use in the database BLOB Type stores large object data , Usually the picture 、 Audio and video files are stored on the disk of the server , And put the picture 、 The access paths of audio and video are stored in MySQL in .
边栏推荐
猜你喜欢

Network security - use exchange SSRF vulnerabilities in combination with NTLM trunking for penetration testing

网络安全——中间人攻击渗透测试

Sringboot plugin framework implements pluggable plug-in services

JS execution mechanism

Network security - file upload penetration test

Icml2022 | branch reinforcement learning

群体知识图谱:分布式知识迁移与联邦式图谱推理

在EXCEL表格中如何进行快速换行

Paper notes: swing UNET: UNET like pure transformer for medicalimage segmentation

The scroll bar in unity ugui is not displayed from the top when launching the interface in the game
随机推荐
网络安全——WAR后门部署
JS execution mechanism
Adjust the array order so that odd numbers precede even numbers
Can communication protocol (I)
Nmap安全测试工具使用教程
MPLS中的包交换和标签交换
基于典型相关分析的多视图学习方法综述
关于不定方程解的个数的问题
R language uses the sum function of epidisplay package to calculate the descriptive statistical summary information of the specified variables in dataframe under different grouping variables, visualiz
【无标题】
在LNMP架构中搭建Zabbix监控服务
Simple order management system small exercise
Spelling words~
网络安全——文件上传白名单绕过
Why are there "two abstract methods" in the functional interface comparator?
The KAP function of epidisplay package in R language calculates the value of kappa statistics (total consistency, expected consistency), analyzes the consistency of the results of multiple scoring obj
Network security - use exchange SSRF vulnerabilities in combination with NTLM trunking for penetration testing
Network security - Web information collection
Exploration of sustainable learning ability to support the application of ecological evolution of Pengcheng series open source large models
Network security - file upload blacklist bypass