MySQL 데이터베이스 / 테이블 / 열이 어떤 문자 집합인지 어떻게 알 수 있습니까?
다음에 대한 (기본값) 문자 세트는 무엇입니까?
MySQL 데이터베이스
MySQL 테이블
MySQL 열
방법은 다음과 같습니다.
스키마의 경우 :
SELECT default_character_set_name FROM information_schema.SCHEMATA
WHERE schema_name = "schemaname";
테이블의 경우 :
SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,
information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
AND T.table_schema = "schemaname"
AND T.table_name = "tablename";
열의 경우 :
SELECT character_set_name FROM information_schema.`COLUMNS`
WHERE table_schema = "schemaname"
AND table_name = "tablename"
AND column_name = "columnname";
대한 열 :
SHOW FULL COLUMNS FROM table_name;
대한 데이터베이스 :
USE your_database_name;
show variables like "character_set_database";
-- or:
-- show variables like "collation_database";
Cf. 이 페이지 . 그리고 MySQL 매뉴얼을 확인하십시오.
서버에있는 모든 데이터베이스의 경우 :
mysql> SELECT SCHEMA_NAME 'database', default_character_set_name 'charset', DEFAULT_COLLATION_NAME 'collation' FROM information_schema.SCHEMATA;
산출:
+----------------------------+---------+--------------------+
| database | charset | collation |
+----------------------------+---------+--------------------+
| information_schema | utf8 | utf8_general_ci |
| my_database | latin1 | latin1_swedish_ci |
...
+----------------------------+---------+--------------------+
A에 대한 하나의 데이터베이스 :
mysql> USE my_database;
mysql> show variables like "character_set_database";
산출:
+----------------------------+---------+
| Variable_name | Value |
+----------------------------+---------+
| character_set_database | latin1 |
+----------------------------+---------+
테이블에 대한 데이터 정렬 가져 오기 :
mysql> USE my_database;
mysql> SHOW TABLE STATUS WHERE NAME LIKE 'my_tablename';
또는-테이블 작성에 대한 전체 SQL을 출력합니다.
mysql> show create table my_tablename
열 데이터 정렬 가져 오기 :
mysql> SHOW FULL COLUMNS FROM my_tablename;
산출:
+---------+--------------+--------------------+ ....
| field | type | collation |
+---------+--------------+--------------------+ ....
| id | int(10) | (NULL) |
| key | varchar(255) | latin1_swedish_ci |
| value | varchar(255) | latin1_swedish_ci |
+---------+--------------+--------------------+ ....
들어 테이블 :
SHOW TABLE STATUS
모든 테이블을 나열합니다.
다음을 사용하여 필터링 :
SHOW TABLE STATUS where name like 'table_123';
대한 데이터베이스 :
다음 명령을 사용하십시오.
USE db_name;
SELECT @@character_set_database;
-- or:
-- SELECT @@collation_database;
SELECT TABLE_SCHEMA, TABLE_NAME, CCSA.CHARACTER_SET_NAME AS DEFAULT_CHAR_SET, COLUMN_NAME, COLUMN_TYPE, C.CHARACTER_SET_NAME FROM information_schema.TABLES AS T JOIN information_schema.COLUMNS AS C USING (TABLE_SCHEMA, TABLE_NAME) JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY AS CCSA ON (T.TABLE_COLLATION = CCSA.COLLATION_NAME) WHERE TABLE_SCHEMA=SCHEMA() AND C.DATA_TYPE IN ('enum', 'varchar', 'char', 'text', 'mediumtext', 'longtext') ORDER BY TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME ;
To see default collation of the database:
USE db_name;
SELECT @@character_set_database, @@collation_database;
To see collation of the table:
SHOW TABLE STATUS where name like 'table_name';
To see collation of the columns:
SHOW FULL COLUMNS FROM table_name;
I always just look at SHOW CREATE TABLE mydatabase.mytable
.
For the database, it appears you need to look at SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA
.
For tables and columns:
show create table your_table_name
For databases:
SELECT SCHEMA_NAME 'database', default_character_set_name 'charset', DEFAULT_COLLATION_NAME 'collation' FROM information_schema.SCHEMATA;
Example output:
mysql> SELECT SCHEMA_NAME 'database', default_character_set_name 'charset', DEFAULT_COLLATION_NAME 'collation' FROM information_schema.SCHEMATA;
+----------------------------+---------+--------------------+
| database | charset | collation |
+----------------------------+---------+--------------------+
| information_schema | utf8 | utf8_general_ci |
| drupal_demo1 | utf8 | utf8_general_ci |
| drupal_demo2 | utf8 | utf8_general_ci |
| drupal_demo3 | utf8 | utf8_general_ci |
| drupal_demo4 | utf8 | utf8_general_ci |
| drupal_demo5 | latin1 | latin1_swedish_ci |
...
+----------------------------+---------+--------------------+
55 rows in set (0.00 sec)
mysql>
For databases:
SHOW CREATE DATABASE "DB_NAME_HERE";
In creating a Database (MySQL), default character set/collation is always LATIN, instead that you have selected a different one on initially creating your database
As many wrote earlier, SHOW FULL COLUMNS should be the preferred method to get column information. What's missing is a way to get charset after that without reaching metadata tables directly:
SHOW FULL COLUMNS FROM my_table WHERE Field = 'my_field'
SHOW COLLATION WHERE Collation = 'collation_you_got'
'Program Tip' 카테고리의 다른 글
C #을 사용하여 .NET에서 현재 사용자 이름을 얻으려면 어떻게해야합니까? (0) | 2020.10.03 |
---|---|
Node.js 배포 설정 / 구성 파일을 저장하는 방법은 무엇입니까? (0) | 2020.10.02 |
이론적으로 사이클 당 최대 4 개의 FLOP을 달성하려면 어떻게해야합니까? (0) | 2020.10.02 |
부트 스트래핑이란 무엇입니까? (0) | 2020.10.02 |
C # 인터페이스. (0) | 2020.10.02 |