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 TEXT
types 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 BLOB
columns.
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
BLOB
andTEXT
columns, you must specify an index prefix length. ForCHAR
andVARCHAR
, a prefix length is optional. See Section 8.3.5, “Column Indexes”.BLOB
andTEXT
columns cannot haveDEFAULT
values.
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_length
bytes of the column are used when sorting. The default value ofmax_sort_length
is 1024. You can make more bytes significant in sorting or grouping by increasing the value ofmax_sort_length
at server startup or runtime. Any client can change the value of its sessionmax_sort_length
variable:mysql>
SET max_sort_length = 2000;
mysql>SELECT id, comment FROM t
->ORDER BY comment;
Instances of
BLOB
orTEXT
columns 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 theMEMORY
storage 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 includeBLOB
orTEXT
columns in the query result only if they are really needed. For example, avoid usingSELECT *
, which selects all columns.The maximum size of a
BLOB
orTEXT
object 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_packet
variable, 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_packet
value. 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 之 ...
随机推荐
- php中生成树形菜单
废话不多说!上代码 class tree { /** * 生成树型结构所需要的2维数组 * @var array */ var $arr = array(); /** * 生成树型结构所需修饰符号,可 ...
- ActiveMQ面试题
什么是activemq activeMQ是一种开源的,实现了JMS1.1规范的,面向消息(MOM)的中间件,为应用程序提供高效的.可扩展的.稳定的和安全的企业级消息通信. activemq的作用以及原 ...
- python 爬虫的一些使用技巧
1.最基本的抓站 import urllib2 content = urllib2.urlopen('http://XXXX').read() -2.使用代理服务器这在某些情况下比较有用,比如IP被封 ...
- Robot Framework接口测试(4)
现在我们已经做好了进行接口测试的必要准备:1.拼接发送的报文:2.发送报文的方法.现在我们实现RF上的接口测试. 我们先对发送的方法进行一下封装: 1.拼接报文方法: #coding : utf-8 ...
- 剑指offer-第六章面试中的各项能力(圆圈中剩下的最后数字)
import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util ...
- openfaas cli 安装
1. 安装脚本 curl -sL https://cli.get-faas.com/ | sudo sh 备注安装完成之后如果没有 faas-cli 可以下载脚本,手工执行 2. 使用二进制 ...
- fn project 私有镜像发布
1. 说明 fnproject 默认的docker registry 是 dockerhub 对于企业应用还是不太方便的 还好系统系统了配置参数方便我们进行配置,与开源harbor 进行集成 2. 使 ...
- mysql权限验证流程
mysql用户管理,逐级下查 mysql库的user表连接信息,全局权限db表记录用户对库的权限,对某个数据库的所有表的权限tables_priv 设置用户对表的权限columns_priv设置用户对 ...
- php小算法总结一(数组重排,进制转换,二分查找)
1.两个有序数组组合成一个新的有序数组 <?php $arr1=array(2,5,7,9,12); $arr2=array(3,4,6,8,10,11); function merge_sor ...
- 菜鸟天天不懂,那就天天敲它。。。还不懂。。。JAVA数组比较大小。
package com.aini; import java.util.Scanner; //操...为什么数组的大小比较我硬是搞不懂,比较大小依然放在for循环里... //从键盘输入一组数据,并输出 ...