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. validate参数校验和数据回显

    服务端校验 校验理解 项目中,通常使用较多的是前段的校验,比如在页面中js校验.对于安全要求较高的建议在服务端进行校验. 服务端校验: 控制层controller:校验页面请求的参数的合法性.在服务端 ...

  2. react 项目及视频

    项目     视频

  3. Android面试题整理

    1.    请描述下Activity的生命周期. 2.    如果后台的Activity由于某原因被系统回收了,如何在被系统回收之前保存当前状态? 3.    如何将一个Activity设置成窗口的样 ...

  4. linux 段错误常见处理方法

    1.如果没有产生core文件,可以查询系统log 通过 sudo cat /var/log/messages |grep segfault 或者 sudo dmesg|grep segfault 获得 ...

  5. 旧书重温:0day2【8】狙击windows的异常处理实验

    现在进入0day2的第六章内容 其中第六章的书本内容我都拍成了图片格式放在了QQ空间中(博客园一张一传,太慢了)http://user.qzone.qq.com/252738331/photo/V10 ...

  6. 在spring配置文件中的 <context:property-placeholder/>用途

    location属性为 具体配置文件的classpath:地址 (可以取配置文件中的值利用${key}的形式,而不用多次写值) 1.这样一来就可以为spring配置的bean的属性设置值了,比如spr ...

  7. IntelliJ IDEA下SVN配置及使用

    一.在IDEA中使用SVN,首先需要下载安装 TortoiseSVN 插件. 打开 TortoiseSVN 下载地址,选择适合自己的系统类型下载. 接下来,进行安装即可.选择Modify,默认 com ...

  8. eclipse share project到svn时显示不被信任的证书,暂时接受也不行

    svn: 方法 OPTIONS 失败于 “https://eping.net/svn/testproject”: SSL handshake failed: SSL 错误:在证书中检测到违规的密钥用法 ...

  9. Fiddler的Java抓包

    代码处理 System.setProperty("http.proxySet", "true"); System.setProperty("http. ...

  10. 关于UNIDAC连接SQLITE3的心得笔记

    关于查询某个SQLITE3DB的所有表单的语句: UniQuery1.SQL.Add('SELECT * FROM sqlite_master'); 关于UNIDAC提交数据: //在提交数据之前,必 ...