如何在BLOB中存储图像?

Joh*_*nna -1 mysql sql blob image

我找不到有关如何将图像存储到BLOB中的有用代码,请帮我一些代码,还可以在GUI中将这些图像从MySQL显示到我的桌面窗格中吗?

Dan*_*llo 6

如果映像位于MySQL主机上,则可以使用该LOAD_FILE()命令在BLOB中存储映像:

-- Using the following table as an example:
CREATE TABLE MyTable (
   image  BLOB
);

-- This will insert a file in a BLOB column.
INSERT INTO MyTable (image) VALUES(LOAD_FILE('/tmp/image.png'));
Run Code Online (Sandbox Code Playgroud)

确保MySQL可以读取映像文件,并确保您的MySQL用户具有该FILE权限.

要授予FILE权限,请以root用户身份登录并执行:

GRANT FILE ON *.* TO 'mysql_user'@'localhost';
Run Code Online (Sandbox Code Playgroud)