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

BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOBBLOB,MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXTtypes are TINYTEXTTEXTMEDIUMTEXT, 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:

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:

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类型的更多相关文章

  1. 【mysql】Blob类型

    来源:http://qgyang.blog.sohu.com/115847378.html 一般在需要存储较大数据时使用Bolb MySql的Bolb四种类型 MySQL中,BLOB是一个二进制大型对 ...

  2. MySQL的BLOB类型(解决mysql不支持mb4编码的时候存储emoji表情问题)

    今天在存储emoji表情的时候,发现无法存储,mysql版本太低也没办法使用uft8mb4格式编码,只能将数据字段设置为blob BLOB是一个二进制大对象,可以容纳可变数量的数据.有4种BLOB类型 ...

  3. mysql存取blob类型数据

    参考网址:http://www.cnblogs.com/jway1101/p/5815658.html 首先是建表语句,需要实现将表建立好. CREATE TABLE `blobtest` ( `pr ...

  4. java 将mysql中Blob类型转为字符串或数字

    引入Blob类型貌似不行,不知道是版本问题还是java中的Blob类型为oracle,后来使用byte[]转换成功. public float byte2float(byte[] b) { if(b! ...

  5. MySQL的Blob类型的手工编辑(manually edit)

    https://dba.stackexchange.com/questions/17593/in-mysql-how-to-manually-edit-values-of-a-blob-column- ...

  6. 附件上传——mysql blob类型的数据(springboot)1

    作为一个初出茅庐的菜鸟,这几天做了一下附件的上传与下载,附件文件存储在mysql中,数据类型为blob.在此做一下总结.望指正. 一.先总结附件的上传.(实质是将文件传到controller,后处理成 ...

  7. MySQL有四种BLOB类型

    先说明一下Blob的类型,直接从网上摘抄了!!!1.MySQL有四种BLOB类型: ·tinyblob:仅255个字符 ·blob:最大限制到65K字节 ·mediumblob:限制到16M字节 ·l ...

  8. mysql截取longblob类型字段内一小块数据的方法

    由于longblob类型的字段内容一般都好大,最大限制是4G,所以在数据查询中读取一整块数据的方式是不现实的,这需要要截取的方法来获取需要的数据. 方法如下: hex(substring(A, ind ...

  9. MySQL中varchar类型在5.0.3后的变化

    1.mysql varchar类型变化:mysql 5.0.3 之前: 0--255字节 varchar(20)中的20表示字节数,如果存放urf8编码的话只能放6个汉字. MySQL 5.0.3 之 ...

随机推荐

  1. 【git】新建一个git仓库的方法

    1.在github上登陆,新建一个远程仓库 2.在本地创建仓库 3.本地仓库关联到远程仓库 git remote add origin(仓库名) git@github.com:yesuuu/test. ...

  2. 升级Tensorflow到1.2版本

    TensorFlow 今天发布最新版 1.2.0,公布了14大最新功能.新智元带来最新介绍,包括 API 的重要变化.contrib API的变化和Bug 修复及其他改变.附代码链接. 主要的功能和改 ...

  3. [Beego] 内置的模板函数(不同格式的字符串和html的互转)

    在使用beego框架的时候,常常需要把不同形式的字符串转化为html,有时候为了安全考虑会将html转义,而有时候希望能显示html标签.在存储到db中后,再取出来的显示是原本的,即html标签不会生 ...

  4. 查看 nginx 的并发连接数

    通过查看Nginx的并发连接,我们可以更清除的知道网站的负载情况.Nginx并发查看有两种方法(之所以这么说,是因为笔者只知道两种),一种是通过web界面,一种是通过命令,web查看要比命令查看显示的 ...

  5. 【sqlite】判断sqlite数据库表是否存在

    SQLite语句: cmd.CommandText = "SELECT count(*) from sqlite_master where type='table' and name='ta ...

  6. CF311B Cats Transport

    题意 Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straigh ...

  7. jQuery火箭图标返回顶部代码

    在网上找来段使用jQuery火箭图标返回顶部代码,感觉比较酷,比较炫,大概样式如下, 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. ...

  8. js客户端UI框架

    Best jQuery UI http://b-jui.com/ jQuery EasyUI http://www.jeasyui.com/ bootstrap学习网: http://www.runo ...

  9. Linux环境安装nginx

    安装需要以下工具: yum -y install gcc gcc-c++ autoconf automake 模块依赖: yum -y install zlib zlib-devel openssl ...

  10. FastAdmin 一键 CRUD 生成时方法不存在的问题分析

    FastAdmin 一键 CRUD 生成时方法不存在的问题分析 有群友反馈 使用 一键 CRUD 生成时不成功. 我试了以下命令 php think crud -t test -u 1 是成功的. 再 ...