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/).

最新文章

  1. offsetWidth、clientWidth、width、scrollWidth区别及js与jQuery获取的方式
  2. 网络粘贴---Xcode中可用到的快捷键
  3. javascript笔记——label包含的自定义按钮选中
  4. POJ 1879 Tempus et mobilius Time and motion 队列和栈
  5. SWFLoader交互
  6. AjaxHelper学习,ajax,microsoft,mvc,asp.net
  7. Dungeon Master poj 2251 dfs
  8. WPF将RGB转为HSL的工具类
  9. mysql limit 接收变量
  10. 某公司基于FineBI数据决策平台的试运行分析报告
  11. Golang随机数生成
  12. SQLServer事务在C#当中的应用
  13. HeadFirstPython学习笔记——OSError: [WinError 10013] 以一种访问权限不允许的方式做了一个访问套接字的尝试。
  14. MySQL数据库事务各隔离级别加锁情况--read committed && MVCC
  15. 使用KeePass管理两步验证
  16. 启动项目时出现java.io.EOFException异常。
  17. js实现60秒倒计时效果(使用了jQuery)
  18. tomcat 启用NIO
  19. MySQL 大数据量使用limit分页,随着页码的增大,查询效率越低下。
  20. HDU 4268 Alice and Bob 贪心STL O(nlogn)

热门文章

  1. mcake活动维护常见问题记录【wap端】 ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
  2. H264子宏块的划分有哪些?
  3. 大白话讲解如何给github上项目贡献代码
  4. 使用jenkins并发布应用到tomcat
  5. 该文档举例说明了multimap的查找和删除元素的使用
  6. MySql必知必会实战练习(五)存储过程
  7. 浅析Python中bytes和str区别
  8. bzoj 3195 奇怪的道路
  9. Servlet、Filter、Listener
  10. 关于ant及svnant的一点随记