简体   繁体   English

错误:MySQL中第1行的“ MEDIUMBLOB”列的数据“ imagen”的数据过长

[英]Error: Data too long for column 'imagen' at row 1 with column 'MEDIUMBLOB' in MySQL

I'm storing images ranging from 1MB and maximum 7mb in a MySQL database. 我正在MySQL数据库中存储从1MB到最大7mb的图像。 To do this I created a table with a field MEDIUMBLOB type having a capacity of 16,777,215 bytes which is the same 16mb. 为此,我创建了一个字段为MEDIUMBLOB类型的表,该表的容量为16777215 字节 ,即16mb。 When I save images up to 2.2MB it is perfectly stored, but when saving images larger but not exceeding the 7mb get the following error: 当我保存不超过2.2MB的图像时,它可以完美存储,但是当保存较大但不超过7mb的图像时,出现以下错误:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: 
Data too long for column 'imagen' at row 1

This is the definition of the image field in my entity image: 这是我的实体图像中图像字段的定义:

@Entity
@Access(AccessType.FIELD)
@Table(name = "Imagen")
@XmlRootElement
public class Imagen implements Serializable {
    // otros campos
    @Lob
    @Column(name = "imagen", columnDefinition = "mediumblob")
    private byte[] imagen;

   // getters and setters
}

My repository class: 我的存储库类:

public interface ImagenRepository extends BaseRepository<Imagen, Integer> {

    // other query operations

}

Base class repository: 基类存储库:

@NoRepositoryBean
public interface BaseRepository<T, ID extends Serializable> extends Repository<T, ID>, Finder<T>, Counter {

    public T save(T save);

    public void delete(ID id);

    public void delete(T entity);

    public Optional<T> findOne(ID id);

}

Image table: 图片表:

CREATE TABLE Imagen (
    id INT(10) NOT NULL AUTO_INCREMENT,
    -- Otros campos
    imagen MEDIUMBLOB,
    type VARCHAR(10) COLLATE UTF8_SPANISH_CI,
    PRIMARY KEY (id)
);

For query operations and persistence use spring-data-jpa. 对于查询操作和持久性,请使用spring-data-jpa。

I do not understand why not save images of more than 2.2MB, please help 我不明白为什么不保存超过2.2MB的图像,请帮助

You might need to increase your server settings for innodb_log_file_size in my.cnf. 您可能需要在my.cnf中增加innodb_log_file_size的服务器设置。 Then restart MySQL. 然后重启MySQL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM