MySQL的blob类型
MySQL中的Blob类型
MySQL中存放大对象的时候,使用的是Blob类型。所谓的大对象指的就是图片,比如jpg、png、gif等格式的图片,文档,比如pdf、doc等,以及其他的文件。为了在数据库中存放这些文件,数据库软件中一般都支持blob类型,用来把这些文档的二进制数据存入其中。
目录
1、大对象介绍
2、MySQL中如何存储大对象
3、MySQL中Blob类型的使用,创建blob类型的字段,插入blob数据,查询blob数据
1、大对象介绍
===============
参考资料:
1、https://stackoverflow.com/questions/9109112/insert-file-into-mysql-blob
2、https://www.cnblogs.com/audi-car/p/6741524.html
3、https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/blob.html
11.4.3 The BLOB and TEXT Types
A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB,MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXTtypes are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements. See Section 11.8, “Data Type Storage Requirements”.
BLOB values are treated as binary strings (byte strings). They have the binary character set and collation, and comparison and sorting are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set other than binary, and values are sorted and compared based on the collation of the character set.
If strict SQL mode is not enabled and you assign a value to a BLOB or TEXT column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode. See Section 5.1.10, “Server SQL Modes”.
Truncation of excess trailing spaces from values to be inserted into TEXT columns always generates a warning, regardless of the SQL mode.
For TEXT and BLOB columns, there is no padding on insert and no bytes are stripped on select.
If a TEXT column is indexed, index entry comparisons are space-padded at the end. This means that, if the index requires unique values, duplicate-key errors will occur for values that differ only in the number of trailing spaces. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error. This is not true for BLOBcolumns.
In most respects, you can regard a BLOB column as a VARBINARY column that can be as large as you like. Similarly, you can regard a TEXT column as a VARCHAR column. BLOB and TEXT differ from VARBINARY and VARCHAR in the following ways:
For indexes on
BLOBandTEXTcolumns, you must specify an index prefix length. ForCHARandVARCHAR, a prefix length is optional. See Section 8.3.5, “Column Indexes”.BLOBandTEXTcolumns cannot haveDEFAULTvalues.
If you use the BINARY attribute with a TEXT data type, the column is assigned the binary (_bin) collation of the column character set.
LONG and LONG VARCHAR map to the MEDIUMTEXT data type. This is a compatibility feature.
MySQL Connector/ODBC defines BLOB values as LONGVARBINARY and TEXT values as LONGVARCHAR.
Because BLOB and TEXT values can be extremely long, you might encounter some constraints in using them:
Only the first
max_sort_lengthbytes of the column are used when sorting. The default value ofmax_sort_lengthis 1024. You can make more bytes significant in sorting or grouping by increasing the value ofmax_sort_lengthat server startup or runtime. Any client can change the value of its sessionmax_sort_lengthvariable:mysql>
SET max_sort_length = 2000;mysql>SELECT id, comment FROM t->ORDER BY comment;Instances of
BLOBorTEXTcolumns in the result of a query that is processed using a temporary table causes the server to use a table on disk rather than in memory because theMEMORYstorage engine does not support those data types (see Section 8.4.4, “Internal Temporary Table Use in MySQL”). Use of disk incurs a performance penalty, so includeBLOBorTEXTcolumns in the query result only if they are really needed. For example, avoid usingSELECT *, which selects all columns.The maximum size of a
BLOBorTEXTobject is determined by its type, but the largest value you actually can transmit between the client and server is determined by the amount of available memory and the size of the communications buffers. You can change the message buffer size by changing the value of themax_allowed_packetvariable, but you must do so for both the server and your client program. For example, both mysql and mysqldump enable you to change the client-sidemax_allowed_packetvalue. See Section 5.1.1, “Configuring the Server”, Section 4.5.1, “mysql — The MySQL Command-Line Tool”, and Section 4.5.4, “mysqldump — A Database Backup Program”. You may also want to compare the packet sizes and the size of the data objects you are storing with the storage requirements, see Section 11.8, “Data Type Storage Requirements”
Each BLOB or TEXT value is represented internally by a separately allocated object. This is in contrast to all other data types, for which storage is allocated once per column when the table is opened.
In some cases, it may be desirable to store binary data such as media files in BLOB or TEXT columns. You may find MySQL's string handling functions useful for working with such data. See Section 12.5, “String Functions”. For security and other reasons, it is usually preferable to do so using application code rather than giving application users the FILE privilege. You can discuss specifics for various languages and platforms in the MySQL Forums (http://forums.mysql.com/).
MySQL的blob类型的更多相关文章
- 【mysql】Blob类型
来源:http://qgyang.blog.sohu.com/115847378.html 一般在需要存储较大数据时使用Bolb MySql的Bolb四种类型 MySQL中,BLOB是一个二进制大型对 ...
- MySQL的BLOB类型(解决mysql不支持mb4编码的时候存储emoji表情问题)
今天在存储emoji表情的时候,发现无法存储,mysql版本太低也没办法使用uft8mb4格式编码,只能将数据字段设置为blob BLOB是一个二进制大对象,可以容纳可变数量的数据.有4种BLOB类型 ...
- mysql存取blob类型数据
参考网址:http://www.cnblogs.com/jway1101/p/5815658.html 首先是建表语句,需要实现将表建立好. CREATE TABLE `blobtest` ( `pr ...
- java 将mysql中Blob类型转为字符串或数字
引入Blob类型貌似不行,不知道是版本问题还是java中的Blob类型为oracle,后来使用byte[]转换成功. public float byte2float(byte[] b) { if(b! ...
- MySQL的Blob类型的手工编辑(manually edit)
https://dba.stackexchange.com/questions/17593/in-mysql-how-to-manually-edit-values-of-a-blob-column- ...
- 附件上传——mysql blob类型的数据(springboot)1
作为一个初出茅庐的菜鸟,这几天做了一下附件的上传与下载,附件文件存储在mysql中,数据类型为blob.在此做一下总结.望指正. 一.先总结附件的上传.(实质是将文件传到controller,后处理成 ...
- MySQL有四种BLOB类型
先说明一下Blob的类型,直接从网上摘抄了!!!1.MySQL有四种BLOB类型: ·tinyblob:仅255个字符 ·blob:最大限制到65K字节 ·mediumblob:限制到16M字节 ·l ...
- mysql截取longblob类型字段内一小块数据的方法
由于longblob类型的字段内容一般都好大,最大限制是4G,所以在数据查询中读取一整块数据的方式是不现实的,这需要要截取的方法来获取需要的数据. 方法如下: hex(substring(A, ind ...
- MySQL中varchar类型在5.0.3后的变化
1.mysql varchar类型变化:mysql 5.0.3 之前: 0--255字节 varchar(20)中的20表示字节数,如果存放urf8编码的话只能放6个汉字. MySQL 5.0.3 之 ...
随机推荐
- react: redux-devTools
import {composeWithDeTools} from 'redux-devtools-extension'; const bindMiddleware = middleware => ...
- Agilent RF fundamentals (8) Oscillator Decisions
----------------------
- 【tensorflow:Google】一、深度学习简介
参考文献:<Tensorflow:实战Google深度学习框架> [一]深度学习简介 1.1 深度学习定义 Mitchell对机器学习的定义:任务T上,随着经验E的增加,效果P也可以随之增 ...
- MASM 16位汇编程序几种典型的格式
1.有名段 data segment output db 'Hello world!$' data ends code segment start: assume ds:data,cs:code mo ...
- 重读tcp-ip详解三卷:1
应用层 Http.Telnet.FTP和e-mail等 负责把数据传输到传输层或接收从传输层返回的数据传输层 TCP和UDP 主要为两台主机上的应用程序提供端到端的通信,TCP为两台主机提供高可靠性的 ...
- 第二章 Linux目录介绍
一级目录 /bin (普通用户)二进制命令所在目录 备注 /boot LINUX内核及系统引导程序所需的文件目录 常见分区:128M swap内存的1.5倍 /dev 设备文件的目录 比如声卡.磁盘. ...
- 高级C/C++编译技术之读书笔记(三)之动态库设计
最近有幸阅读了<高级C/C++编译技术>深受启发,该书深入浅出地讲解了构建过程(编译.链接)中的各种细节,从多个角度展示了程序与库文件或代码的集成方法,提出了面向代码复用和系统集成的软件架 ...
- PS基础教程[3]如何去除照片上的水印
网络上的照片大部分都有很多的水印,要嘛就是网站的地址,要嘛就是一些煽情的文字,我们看图片想要的可不是这些东西,那么我们怎样去掉图片上的水印呢?本次我们就来分享一下仿制图章工具的使用. 方法 1.打开P ...
- 互联网公司面试必问的mysql题目(下)
这是mysql系列的下篇,上篇文章地址我附在文末. 什么是数据库索引?索引有哪几种类型?什么是最左前缀原则?索引算法有哪些?有什么区别? 索引是对数据库表中一列或多列的值进行排序的一种结构.一个非常恰 ...
- 【Spring】Junit加载Spring容器作单元测试(整理)
[Spring]Junit加载Spring容器作单元测试 阅读目录 >引入相关Jar包 > 配置文件加载方式 > 原始的用法 > 常见的用法 > 引入相关Jar包 一.均 ...