MySQL 컬럼 자료형 확인

Jmnote (토론 | 기여)님의 2015년 6월 24일 (수) 11:29 판 (→‎방법 3: PHP)
MySQL 컬럼 자료형 확인

1 방법 1: SHOW COLUMNS

mysql> SHOW COLUMNS FROM `user` LIKE 'user_id';
+---------+------------------+------+-----+---------+----------------+
| Field   | Type             | Null | Key | Default | Extra          |
+---------+------------------+------+-----+---------+----------------+
| user_id | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
+---------+------------------+------+-----+---------+----------------+
1 row in set (0.00 sec)

2 방법 2: information_schema

mysql> SELECT DATA_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME='user' AND COLUMN_NAME='user_id';
+-----------+
| DATA_TYPE |
+-----------+
| int       |
+-----------+
1 row in set (0.00 sec)
mysql> SELECT COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME='user' AND COLUMN_NAME='user_id';
+------------------+
| COLUMN_TYPE      |
+------------------+
| int(10) unsigned |
+------------------+
1 row in set (0.00 sec)

3 방법 3: PHP

$mysqli = new mysqli('localhost','my_user','my_password','world');
$result = $mysqli->query("SHOW COLUMNS FROM `테이블명` LIKE '컬러명'");
$row = mysqli_fetch_assoc($result);
$column_type = $row['Type'];

4 같이 보기

5 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}