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. ngxtop实时监控nginx状态

    ngxtop实时解析nginx访问日志,并且将处理结果输出到终端,功能类似于系统命令top,所以这个软件起名ngxtop.有了ngxtop,你可以实时了解到当前nginx的访问状况,再也不需要tail ...

  2. SQLServer2008导入Excel遇到的问题

    今天同事给客户处理基础物料信息,要把Excel中的几千行物料信息导入到数据库.觉得不是啥难事,写个SQL语句而已,没成想,实际一操作,出问题了. SELECT * FROM OPENROWSET('M ...

  3. 【前端】CSS入门笔记

    教程 CSS 指层叠样式表 (Cascading Style Sheets) CSS 语法 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 选择器通常是您需要改变样式的 HTML 元素 ...

  4. [leetcode]_Binary Tree Level Order Traversal I && II

    题目:给定一棵二叉树,对其进行层次遍历,将遍历结果存入二维链表中. 思路:二叉树的层次遍历关键在于使用Queue. 复习: Queue的定义.LinkedList实现了Queue接口,因此可用Link ...

  5. Python基本特殊方法之__format__

    __format__()方法 __format__()传参方法:someobject.__format__(specification) specification为指定格式,当应用程序中出现&quo ...

  6. TortoiseGit不同分支合并代码2

    现在有主分支master和分支day2.现在要把day2上的变更合并到主分支master上! 1.首先切换到目标分支master上. 说明当前分支是master分支. 2.在master分支上查看提交 ...

  7. JMeter启动时显示Could not open/create prefs root node Software\JavaSoft\Prefs at root 0X80000002

    在windows 7上启动jmeter时,提示错误: Java.util.prefs.WindowsPreferences <init> WARNING: Could not open/c ...

  8. python使用wxPython创建一个简单的文本编辑器。

    ubuntu下通过'sudo apt-get install python-wxtools'下载wxPython.load和save函数用于加载和保存文件内容,button通过Bind函数绑定这两个函 ...

  9. plsql无法连接64位oracle数据库的解决方法

    今儿个重装了个系统,win8 64位.接着装了个64位的oracle11g,oracle11g下载页面:http://www.oracle.com/technetwork/database/enter ...

  10. 关于在windows server 2008 上部署wampserver2.5部署的问题

    1.关闭windows自带防火墙 2.httpd.conf文件权限 apache 2.4.9 外网访问的问题参考此文: http://blog.csdn.net/lysc_forever/articl ...