MySQL
-
[ php ] csv 파일 테이블로 import 하기 ( LOAD DATA INFILE )프로그래밍/PHP 2017. 10. 2. 20:18
디렉토리에 들어있는 csv 파일들을 DB에 저장할 일이 생겼다. 파일 개수가 많아 php로 파일 리스트를 읽어 테이블들로 일괄 저장하려고 한다. mysqlimport도 생각해봤는데 LOAD DATA INFILE 문 처리속도가 더 빠르다고 한다. 일단 DB에 접속하자. $conn = mysqli_connect('localhost', 'userid', 'password','dbname'); if (mysqli_connect_errno($conn)) echo "데이터베이스 연결 실패: " . mysqli_connect_error(); else echo "connection success"; csv파일을 import할 테이블도 생성하자. 기존 csv파일에 없는 idx필드를 생성해 primary key값으로 설정..
-
mysql int 타입 최대/최소 값프로그래밍/DB 2017. 10. 1. 18:22
매번 테이블 만들때마다 검색하기 귀찮아서 걍 블로그 저장용 MySQL supports the SQL standard integer types INTEGER (or INT) and SMALLINT. As an extension to the standard, MySQL also supports the integer types TINYINT, MEDIUMINT, and BIGINT. The following table shows the required storage and range for each integer type. 참조: http://dev.mysql.com/doc/refman/5.5/en/integer-types.htmlhttps://zetawiki.com/wiki/MySQL_%EC%9E%90%EB..
-
mysql 두 개의 테이블 데이터 사용하기 예시들프로그래밍/DB 2017. 9. 30. 18:22
두 개의 테이블에서 칼럼들 읽어오기 (inner join) SELECT t1.*, t2.*FROM table1 t1, table2 t2WHERE t1.id = t2.t1_id 다른 테이블 정보로 칼럼 데이터 업데이트 하기 UPDATE table1 t1, table2 t2SET t1.field_to_change = t2.field_with_dataWHERE t1.field1 = t2.field2; 다른 테이블 필드 값을 추가하기 INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100; 특정 문자열을 select 문과 같이 사용할 경우에는 select 문의 필드명에서..