Database

Mysql 유용한 팁

Jack Moon 2022. 9. 1. 09:50

1) 날짜 시간 자동 입력

crawldate 에 crawling 시간을 자동으로 입력하고 싶다. => not null, default 는 CURRENT_TIMESTAMP

 

2) truncate 에러

A 테이블의 pk 가 B 테이블의 fk 로 사용될때 

 truncate A;

 하면 아래와 같은 에러가 뜬다.

Error Code: 1701
Cannot truncate a table referenced in a foreign key constraint

 

이럴 경우

> set FOREIGN_KEY_CHECKS = 0;
Query OK, 0 rows affected (0.000 sec)

> truncate A;

3) autocommit자동 commit 하고 싶다면 아래와 같이 'autocommit' : True 넣으면 된다.

connection = {
    'user' : 'root',
    'password' : '',
    'host' : 'localhost',
    'port' : '3306',
    'database' : 'brandiv1',
    'charset' : 'utfmb4',
    'autocommit' : True
}