mysql - 如何使用MYSQL插入命令将图像添加到phpmyadmin的表中?

标签 mysql sql phpmyadmin

我创建了下表:

CREATE TABLE Movie
(Movie_ID INT NOT NULL AUTO_INCREMENT,
 Movie_Image BLOB NOT NULL,
 Movie_Name VARCHAR(30) UNIQUE NOT NULL,
 Movie_Description TEXT,
 Movie_Genre VARCHAR(20) UNIQUE NOT NULL,
 Movie_Rating VARCHAR(10) UNIQUE NOT NULL,
 Movie_Duration INT NOT NULL,
 PRIMARY KEY (Movie_ID)
 )

然后我尝试插入以下值:

INSERT INTO Movie (Movie_Image, Movie_Name, Movie_Description, Movie_Genre, Movie_Rating, Movie_Duration)
VALUES (LOAD_FILE('E:/justice league.jpg'),'Justice League','Fueled by his restored faith in humanity and inspired by Supermans selfless act, Bruce Wayne enlists newfound ally Diana Prince to face an even greater threat. Together, Batman and Wonder Woman work quickly to recruit a team to stand against this newly awakened enemy. Despite the formation of an unprecedented league of heroes','Action','PG-13',120); 
INSERT INTO Movie (Movie_Image, Movie_Name, Movie_Description, Movie_Genre, Movie_Rating, Movie_Duration)
VALUES (LOAD_FILE('E:/thor.jpg'),'Thor: Ragnarok','Imprisoned on the other side of the universe, the mighty Thor finds himself in a deadly gladiatorial contest that pits him against the Hulk, his former ally and fellow Avenger. Thors quest for survival leads him in a race against time to prevent the all-powerful Hela from destroying his home world and the Asgardian civilization.','Action','PG-13',130); 
INSERT INTO Movie (Movie_Image, Movie_Name, Movie_Description, Movie_Genre, Movie_Rating, Movie_Duration)
VALUES (LOAD_FILE('E:/star wars.jpg'),'Star Wars: The Last Jedi','Luke Skywalkers peaceful and solitary existence gets upended when he encounters Rey, a young woman who shows strong signs of the Force. Her desire to learn the ways of the Jedi forces Luke to make a decision that changes their lives forever.','Action','PG-13',152);

但我收到以下错误:

#1048 - Column 'Movie_Image' cannot be null

如何在MYSQL中通过INSERT命令向表中插入图片? 如果提供解决方案代码将非常有帮助。

最佳答案

来自documentation :

加载文件

读取文件并以字符串形式返回文件内容。要使用此功能,文件必须位于服务器主机上,必须指定文件的完整路径名,并且必须具有 FILE 权限。该文件必须可供所有人读取,并且其大小小于 max_allowed_pa​​cket 字节。如果 secure_file_priv 系统变量设置为非空目录名,则要加载的文件必须位于该目录中。

如果文件不存在或由于不满足上述条件之一而无法读取,则函数返回 NULL。

  1. 检查服务器上提供的位置是否存在该文件。
  2. 检查您的 MySQL 用户是否具有 FILE 权限。
  3. 检查文件是否可供所有人读取。
  4. 检查 max_allowed_pa​​cket 字节的大小 - 并确保其足够大以容纳您的文件。
  5. 检查是否设置了 secure_file_priv。如果是,您需要从该目录加载文件。

关于mysql - 如何使用MYSQL插入命令将图像添加到phpmyadmin的表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48505757/

相关文章:

mysql - gem在rails中安装mysql问题

java - Hibernate 与 JDBC 动态数据库连接

sql - 如何在 Atom Editor 中连接数据库?

mysql - WordPress wpdb->导入数据的查询问题

java - 如何查看/更改 MySQL 连接超时设置?

mysql - 如何向mysql数据库添加多个约束

java - 如何从多个本地网站提取信息?

mysql - 尽管使用 IFNULL (MySQL),SQL 查询也不返回 NULL 值

php 和 mySQL 日期不起作用 - 与美国和欧洲结构有关?

mysql - 如何访问远程服务器上的phpMyAdmin