mysql ER_DATA_TOO_LONG 무시 하는 방법 있나요?

조회수 2194회

mysql 서버를 새로 설치한 상태입니다. 기존에는 문제없이 사용하다가 새로 옮긴 서버에서 mysql 에 insert 할 때 ER_DATA_TOO_LONG 에러를 냅니다.

기존 서버에서는 글자수가 넘어가는 것들은 그냥 짤려서 저장되었는데 새로운 서버에서는 글자수 넘어가면 에러를 내는것 같은데 기존 처럼 그냥 짤려서 저장하게 하는 옵션이 무엇일까요?

1 답변

  • 좋아요

    1

    싫어요
    채택 취소하기

    STRICT_TRANS_TABLES 과 STRICT_ALL_TABLES 을 끄고 시도해보세요. 그러면 자동으로 초과되는 문자열을 truncate 해줄겁니다.

    MySQL 문서 인용:

    Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.) Strict mode also affects DDL statements such as CREATE TABLE.

    모드 변경하기

    SET GLOBAL sql_mode = 'modes';
    SET SESSION sql_mode = 'modes';
    

    현재 모드 확인하기

    SELECT @@GLOBAL.sql_mode;
    SELECT @@SESSION.sql_mode;
    

    예시

    mysql> SET sql_mode=''; ! 모드 끄기
    mysql> SET sql_mode='STRICT_TRANS_TABLES'; ! STRICT_TRANS_TABLES 모드 켜기
    mysql> SET sql_mode='STRICT_ALL_TABLES '; ! STRICT_ALL_TABLES  모드 켜기
    

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)