MySQL插入圖片或pdf檔案到資料庫中(BLOB)--load_file函式
MySQL插入圖片或pdf檔案到資料庫中(BLOB)--load_file函式
Oracle BLOB型別的資料如何檢視和下載?: http://blog.itpub.net/26736162/viewspace-2639269/
在MySQL中可以使用load_file函式處理:
drop table lhrdb.t_image; CREATE table lhrdb.t_image(id int PRIMARY key auto_increment, `img` longblob NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; select * from lhrdb.t_image; insert into lhrdb.t_image(img) values(load_file('/tmp/1.jpg')),(load_file('/tmp/PerconaXtraBackup-2.4.20.pdf')); select load_file('/tmp/1.jpg'),load_file('/tmp/PerconaXtraBackup-2.4.20.pdf') ; select LENGTH(load_file('/tmp/1.jpg')),length(load_file('/tmp/PerconaXtraBackup-2.4.20.pdf')); show variables like '%max_allowed_packet%'; select @@secure_file_priv,@@max_allowed_packet; set GLOBAL max_allowed_packet=1*1024*1024*1024; -- 最新1024,最大1g,5.7預設4M,8.0預設64M 在使用load_file函式時需要注意以下幾點: 1、若沒有載入成功,則會返回空。 2、必須設定引數secure_file_priv,檔案需要放在該引數路徑下 3、Windows環境下的資料夾識別符是 “/”,例如:“select load_file('C:/tmp/1.jpg') ;” 4、被載入的檔案的大小需要小於引數max_allowed_packet的值 5、只能載入MySQL伺服器上的檔案secure_file_priv變數路徑下的檔案
mysqldump之 --hex-blob
該引數將下面資料型別的欄位的資料以十六進位制的形式匯出
- BINARY
- VARBINARY
- BLOB
- BIT
- 以及binary字符集的資料
其中MySQL的BLOB型別可以有如下型別
- tinyblob:僅255個字元
- blob:最大限制到65K位元組
- mediumblob:限制到16M位元組
- longblob:可達4GB
使用Navicat Preminum可以將二進位制資料匯出來
也可以直接使用DBeaver檢視二進位制圖片:
https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_allowed_packet
---- 5.7
Property | Value |
---|---|
Command-Line Format |
--max-allowed-packet=# |
System Variable |
max_allowed_packet |
Scope | Global, Session |
Dynamic | Yes |
Type | Integer |
Default Value |
4194304 |
Minimum Value |
1024 |
Maximum Value |
1073741824 |
The maximum size of one packet or any generated/intermediate string, or any parameter sent by the
mysql_stmt_send_long_data()
C API function. The default is 4MB.
The packet message buffer is initialized to
net_buffer_length
bytes, but can grow up to
max_allowed_packet
bytes when needed. This value by default is small, to catch large (possibly incorrect) packets.
You must increase this value if you are using large
BLOB
columns or long strings. It should be as big as the largest
BLOB
you want to use. The protocol limit for
max_allowed_packet
is 1GB. The value should be a multiple of 1024; nonmultiples are rounded down to the nearest multiple.
When you change the message buffer size by changing the value of the
max_allowed_packet
variable, you should also change the buffer size on the client side if your client program permits it. The default
max_allowed_packet
value built in to the client library is 1GB, but individual client programs might override this. For example,
mysql and
mysqldump have defaults of 16MB and 24MB, respectively. They also enable you to change the client-side value by setting
max_allowed_packet
on the command line or in an option file.
The session value of this variable is read only. The client can receive up to as many bytes as the session value. However, the server will not send to the client more bytes than the current global
max_allowed_packet
value. (The global value could be less than the session value if the global value is changed after the client connects.)
--- 8.0
Property | Value |
---|---|
Command-Line Format |
--max-allowed-packet=# |
System Variable |
max_allowed_packet |
Scope | Global, Session |
Dynamic | Yes |
SET_VAR Hint Applies |
No |
Type | Integer |
Default Value |
67108864 |
Minimum Value |
1024 |
Maximum Value |
1073741824 |
The maximum size of one packet or any generated/intermediate string, or any parameter sent by the
mysql_stmt_send_long_data()
C API function. The default is 64MB.
The packet message buffer is initialized to
net_buffer_length
bytes, but can grow up to
max_allowed_packet
bytes when needed. This value by default is small, to catch large (possibly incorrect) packets.
You must increase this value if you are using large
BLOB
columns or long strings. It should be as big as the largest
BLOB
you want to use. The protocol limit for
max_allowed_packet
is 1GB. The value should be a multiple of 1024; nonmultiples are rounded down to the nearest multiple.
When you change the message buffer size by changing the value of the
max_allowed_packet
variable, you should also change the buffer size on the client side if your client program permits it. The default
max_allowed_packet
value built in to the client library is 1GB, but individual client programs might override this. For example,
mysql and
mysqldump have defaults of 16MB and 24MB, respectively. They also enable you to change the client-side value by setting
max_allowed_packet
on the command line or in an option file.
The session value of this variable is read only. The client can receive up to as many bytes as the session value. However, the server will not send to the client more bytes than the current global
max_allowed_packet
value. (The global value could be less than the session value if the global value is changed after the client connects.)
Reads the file and returns the file contents as a string. To use this function, the file must be located on the server host, you must specify the full path name to the file, and you must have the
FILE
privilege. The file must be readable by all and its size less than
max_allowed_packet
bytes. If the
secure_file_priv
system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.
If the file does not exist or cannot be read because one of the preceding conditions is not satisfied, the function returns
NULL
.
The
character_set_filesystem
system variable controls interpretation of file names that are given as literal strings.
mysql> UPDATE t SET blob_col=LOAD_FILE('/tmp/picture') WHERE id=1;
About Me
........................................................................................................................ ● 本文作者:小麥苗,部分內容整理自網路,若有侵權請聯絡小麥苗刪除 ● 本文在itpub、部落格園、CSDN和個人微 信公眾號( DB寶)上有同步更新 ● 本文itpub地址: http://blog.itpub.net/26736162 ● 本文部落格園地址: http://www.cnblogs.com/lhrbest ● 本文CSDN地址: https://blog.csdn.net/lihuarongaini ● 本文pdf版、個人簡介及小麥苗雲盤地址: http://blog.itpub.net/26736162/viewspace-1624453/ ● 資料庫筆試面試題庫及解答: http://blog.itpub.net/26736162/viewspace-2134706/ ● DBA寶典今日頭條號地址: ........................................................................................................................ ● QQ群號: 230161599 、618766405 ● 微 信群:可加我微 信(lhrbestxh),我拉大家進群,非誠勿擾 ● 聯絡我請加QQ好友 ( 646634621 ),註明新增緣由 ● 於 2020-05-01 06:00 ~ 2020-05-30 24:00 在西安完成 ● 最新修改時間:2020-05-01 06:00 ~ 2020-05-30 24:00 ● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解 ● 版權所有,歡迎分享本文,轉載請保留出處 ........................................................................................................................ ● 小麥苗的微店: ● 小麥苗出版的資料庫類叢書: http://blog.itpub.net/26736162/viewspace-2142121/ ● 小麥苗OCP、OCM、高可用網路班: http://blog.itpub.net/26736162/viewspace-2148098/ ● 小麥苗騰訊課堂主頁: https://lhr.ke.qq.com/ ........................................................................................................................ 請掃描下面的二維碼來關注小麥苗的微 信公眾號( DB寶)及QQ群(230161599、618766405)、新增小麥苗微 信(lhrbestxh), 學習最實用的資料庫技術。
........................................................................................................................ |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2694951/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 檔案插入 Oracle資料庫 Blob型別Oracle資料庫型別
- Android iText向pdf模板插入資料和圖片Android
- 圖片寫入pdf檔案
- vb向資料庫中讀取單個圖片檔案資料庫
- Firedac 在資料表中插入BLOB資料的方法
- Overleaf中插入pdf圖片只顯示圖片路徑的解決方式
- MySQL資料庫中的分組函式ROLLUPMySql資料庫函式
- Oracle插入Blob資料的方法Oracle
- hibernate插入中文到mysql資料庫亂碼MySql資料庫
- MySql資料庫——檔案MySql資料庫
- 道歉,上傳的檔案或圖片等資料被刪除
- Redis從檔案中批量插入資料Redis
- 插入一個檔案到DB中
- PHP 連線 MySQL 資料庫 - 手把手教你搭建學生資訊管理頁,MySQL blob 儲存圖片PHPMySql資料庫
- pdf是圖片還是文件 pdf格式是文字檔案還是影像檔案
- aspose word轉換pdf檔案後將pdf檔案轉換為圖片png
- 將資料庫備份到AZURE blob storage資料庫
- MySQL資料庫中timediff()函式,在瀚高資料庫中如何替換使用?MySql資料庫函式
- 想要提取PDF檔案中的美麗圖片,該怎麼辦?
- mysql資料庫時間戳函式MySql資料庫時間戳函式
- 從資料庫中blob欄位中,下載word檔案,word檔案全是亂碼,怎麼會事啊資料庫
- mongodb資料庫中插入資料MongoDB資料庫
- ssis 寫檔案到資料庫資料庫
- 把csv檔案的資料匯入到oracle資料庫中Oracle資料庫
- Python 在Excel中插入、替換、提取、或刪除圖片PythonExcel
- java poi讀取Excel資料 插入到SQL SERVER資料庫中JavaExcelSQLServer資料庫
- MySQL中如何批次插入資料MySql
- Lazarus中對mysql資料庫Blob型別進行讀寫例子MySql資料庫型別
- .NET 資料庫大資料 方案(插入、更新、刪除、查詢 、插入或更新)資料庫大資料
- 在silverlight中利用socket傳送圖片或檔案
- 想要pdf檔案裡面的圖片,求問pdf格式轉換成jpg?
- 遷移資料庫檔案到ASM資料庫ASM
- Bak檔案恢復到資料庫資料庫
- ios判斷檔案或圖片的型別iOS型別
- java+pgsql實現儲存圖片到資料庫,以及讀取資料庫儲存的圖片JavaSQL資料庫
- python——將excel檔案寫入mysql資料庫中PythonExcelMySql資料庫
- mysql迴圈插入資料、生成隨機數及CONCAT函式MySql隨機函式
- python資料插入連線MySQL資料庫PythonMySql資料庫