IT/MySQL

MySQL 테이블 정보 및 테이블 컬럼 가져오기. 컬럼 합치기.

당양부부34 2018. 1. 16. 16:04

1 테이블 검색.


select * from INFORMATION_SCHEMA.tables 

where table_schema='계정명';

 → show tables;


2. 컬럼 검색.

select * from INFORMATION_SCHEMA.columns 

where table_schema='계정명' 

and table_name='테이블명' 

order by ordinal_position;

 →  show full columns from 테이블명;


3. 컬럼명 한줄로 합치기.

select GROUP_CONCAT(column_name, ' ') from INFORMATION_SCHEMA.columns 

where table_schema='계정명' 

and table_name='테이블명' 


만약 GROUP_CONCAT size 문제로 데이터가 잘릴 경우

  3.1. GROUP_CONCAT size 조회.

  show variables like 'group_concat_max_len';


  3.2. GROUP_CONCAT size 설정.

  SET @@group_concat_max_len = 2048 ;