> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-trino-dialect.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 원격 MySQL 서버의 데이터베이스에 연결하고, ClickHouse와 MySQL 간에 데이터를 주고받기 위해 `INSERT` 및 `SELECT` 쿼리를 수행할 수 있습니다.

# MySQL

export const CloudNotSupportedBadge = () => {
  return <a href="https://clickhouse.com/docs/products/cloud/guides/cloud-compatibility#list-of-unsupported-features" className="cloudNotSupportedBadge">
            <div className="cloudNotSupportedIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.5" d="M6.33366 12.6666L12.3739 12.6667C13.6593 12.6667 14.7073 11.6187 14.7073 10.3334C14.7073 9.04804 13.6593 8.00003 12.3739 8.00003C12.3739 8.00003 12.3337 7.66659 12.0003 7.33325M10.667 5.33322C8.00033 2.33325 4.45395 4.78537 4.14195 6.68203C2.55728 6.7627 1.29395 8.06203 1.29395 9.6667C1.29395 11.3234 2.66699 12.6666 4.00033 12.6666" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.5" d="M2.66699 14L12.0003 4.66663" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>

        </div>
            ClickHouse Cloud에서 지원되지 않음
        </a>;
};

<CloudNotSupportedBadge />

원격 MySQL 서버의 데이터베이스에 연결하고, ClickHouse와 MySQL 간에 데이터를 주고받기 위해 `INSERT` 및 `SELECT` 쿼리를 수행할 수 있습니다.

`MySQL` 데이터베이스 엔진은 쿼리를 MySQL 서버로 전달하므로 `SHOW TABLES`나 `SHOW CREATE TABLE` 같은 작업을 수행할 수 있습니다.

다음 쿼리는 수행할 수 없습니다.

* `RENAME`
* `CREATE TABLE`
* `ALTER`

<div id="creating-a-database">
  ## 데이터베이스 생성
</div>

```sql theme={null}
CREATE DATABASE [IF NOT EXISTS] db_name [ON CLUSTER cluster]
ENGINE = MySQL('host:port', ['database' | database], 'user', 'password')
[SETTINGS enable_compression=0]
```

**엔진 매개변수**

* `host:port` — MySQL 서버 주소입니다.
* `database` — 원격 데이터베이스 이름입니다.
* `user` — MySQL 사용자 이름입니다.
* `password` — 사용자 비밀번호입니다.

**설정**

<div id="enable-compression">
  ### `enable_compression`
</div>

MySQL 프로토콜 connection에 대해 zlib 압축을 활성화합니다. `1`로 설정하면 ClickHouse가 MySQL 서버에 프로토콜 수준의 압축을 요청합니다.

기본값: `0`.

예시:

```sql theme={null}
CREATE DATABASE mysql_db
ENGINE = MySQL('localhost:3306', 'test', 'my_user', 'user_password')
SETTINGS enable_compression = 1;
```

<div id="tls-ssl">
  ## TLS/SSL
</div>

MySQL 암호화 연결의 자격 증명은 [명명된 컬렉션](/ko/concepts/features/configuration/server-config/named-collections)의 키(또는 키-값 인수)로 전달됩니다.

| 매개변수           | 설명                                   |
| -------------- | ------------------------------------ |
| `ssl_ca_pem`   | MySQL 서버 인증서 검증에 사용되는 CA 인증서의 내용입니다. |
| `ssl_cert_pem` | 인증서 기반 인증에 사용하는 클라이언트 인증서의 내용입니다.    |
| `ssl_key_pem`  | `ssl_cert_pem`에 해당하는 프라이빗 키의 내용입니다.  |

값은 해당 PEM 파일의 내용이며, 명명된 컬렉션이나 쿼리에 복사할 수 있습니다. 비밀번호와 마찬가지로 로그 및 `SHOW` 쿼리에서는 마스킹됩니다.

동일한 자격 증명은 서버의 파일 경로를 `ssl_ca`, `ssl_cert`, `ssl_key`에 지정하는 방식으로도 제공할 수 있습니다. 단, **서버 구성 파일에 정의된 명명된 컬렉션에서만** 가능하며, 이러한 값은 쿼리에서 재정의할 수 없습니다. 서버는 자체 권한으로 해당 파일을 열기 때문에 SQL에서 경로를 허용하면 MySQL 소스를 정의할 수 있는 모든 사용자가 로컬 파일 시스템을 탐색하고, 직접 읽을 권한이 없는 인증서와 키를 사용해 인증할 수 있게 됩니다.

<a id="data_types-support" />

<div id="data-types-support">
  ## 데이터 타입 지원
</div>

| MySQL                            | ClickHouse                                                      |
| -------------------------------- | --------------------------------------------------------------- |
| UNSIGNED TINYINT                 | [UInt8](/ko/reference/data-types/int-uint)                      |
| TINYINT                          | [Int8](/ko/reference/data-types/int-uint)                       |
| UNSIGNED SMALLINT                | [UInt16](/ko/reference/data-types/int-uint)                     |
| SMALLINT                         | [Int16](/ko/reference/data-types/int-uint)                      |
| UNSIGNED INT, UNSIGNED MEDIUMINT | [UInt32](/ko/reference/data-types/int-uint)                     |
| INT, MEDIUMINT                   | [Int32](/ko/reference/data-types/int-uint)                      |
| UNSIGNED BIGINT                  | [UInt64](/ko/reference/data-types/int-uint)                     |
| BIGINT                           | [Int64](/ko/reference/data-types/int-uint)                      |
| FLOAT                            | [Float32](/ko/reference/data-types/float)                       |
| DOUBLE                           | [Float64](/ko/reference/data-types/float)                       |
| DATE                             | [Date](/ko/reference/data-types/date)                           |
| DATETIME, TIMESTAMP              | [DateTime](/ko/reference/data-types/datetime)                   |
| BINARY                           | [FixedString](/ko/reference/data-types/fixedstring)             |
| POINT                            | [Point](/ko/reference/data-types/geo#point)                     |
| LINESTRING                       | [LineString](/ko/reference/data-types/geo#linestring)           |
| POLYGON                          | [Polygon](/ko/reference/data-types/geo#polygon)                 |
| MULTILINESTRING                  | [MultiLineString](/ko/reference/data-types/geo#multilinestring) |
| MULTIPOLYGON                     | [MultiPolygon](/ko/reference/data-types/geo#multipolygon)       |
| MULTIPOINT                       | [MultiPoint](/ko/reference/data-types/geo#multipoint)           |
| GEOMETRY                         | [Geometry](/ko/reference/data-types/geo#geometry)               |

공간 타입의 변환은(항상 변환되는 `POINT` 제외) 기본적으로 활성화된 [`mysql_datatypes_support_level`](/ko/reference/settings/session-settings/mysql#mysql_datatypes_support_level) 설정의 `geometry` 플래그로 제어됩니다. 일반 `GEOMETRY` 컬럼 타입은 구체적인 기하 타입을 포괄하는 [`Geometry`](/ko/reference/data-types/geo#geometry) 타입(구체적인 기하 타입에 대한 `Variant`)에 매핑됩니다. 이러한 컬럼에는 모든 하위 타입의 값을 저장할 수 있으므로, ClickHouse에 대응하는 타입이 없는 하위 타입(`GEOMETRYCOLLECTION`)의 값을 읽으면 읽기 시점에 예외가 발생합니다. 적절한 기하 타입을 사용하기 위해 이러한 비호환성은 허용됩니다. `GEOMETRYCOLLECTION` 타입으로 선언된 컬럼은 그 외의 모든 MySQL 데이터 타입과 마찬가지로 [String](/ko/reference/data-types/string)으로 변환됩니다.

[Nullable](/ko/reference/data-types/nullable)을 지원합니다. 공간 컬럼은 다음 3가지 경우 기하 타입 대신 `String`(널 허용인 경우 `Nullable(String)`)에 매핑됩니다. `GEOMETRYCOLLECTION`으로 선언된 경우, `geometry` 플래그가 비활성화되고 타입이 `POINT`가 아닌 경우, 또는 `Point`만 `Nullable` 내부에 중첩할 수 있으므로 컬럼이 널 허용이고 타입이 `POINT`가 아닌 경우입니다. 세 경우 모두 문자열은 MySQL이 반환하는 값 그대로, 즉 4바이트 SRID 접두사 뒤에 WKB payload가 이어지는 형식으로 저장됩니다. 따라서 WKB 디코더에 전달하기 전에 앞의 4바이트를 제거하십시오.

<div id="global-variables-support">
  ## 전역 변수 지원
</div>

호환성을 높이기 위해 전역 변수는 MySQL 방식인 `@@identifier`로 참조할 수 있습니다.

지원되는 변수는 다음과 같습니다:

* `version`
* `max_allowed_packet`

<Note>
  현재로서는 이 변수들이 스텁일 뿐이며 실제로 대응되는 항목은 없습니다.
</Note>

예시:

```sql theme={null}
SELECT @@version;
```

<div id="examples-of-use">
  ## 사용 예시
</div>

MySQL의 테이블:

```text theme={null}
mysql> USE test;
Database changed

mysql> CREATE TABLE `mysql_table` (
    ->   `int_id` INT NOT NULL AUTO_INCREMENT,
    ->   `float` FLOAT NOT NULL,
    ->   PRIMARY KEY (`int_id`));
Query OK, 0 rows affected (0,09 sec)

mysql> insert into mysql_table (`int_id`, `float`) VALUES (1,2);
Query OK, 1 row affected (0,00 sec)

mysql> select * from mysql_table;
+------+-----+
| int_id | value |
+------+-----+
|      1 |     2 |
+------+-----+
1 row in set (0,00 sec)
```

ClickHouse의 데이터베이스로, MySQL 서버와 데이터를 주고받습니다:

```sql theme={null}
CREATE DATABASE mysql_db ENGINE = MySQL('localhost:3306', 'test', 'my_user', 'user_password') SETTINGS read_write_timeout=10000, connect_timeout=100;
```

```sql theme={null}
SHOW DATABASES
```

```text theme={null}
┌─name─────┐
│ default  │
│ mysql_db │
│ system   │
└──────────┘
```

```sql theme={null}
SHOW TABLES FROM mysql_db
```

```text theme={null}
┌─name─────────┐
│  mysql_table │
└──────────────┘
```

```sql theme={null}
SELECT * FROM mysql_db.mysql_table
```

```text theme={null}
┌─int_id─┬─value─┐
│      1 │     2 │
└────────┴───────┘
```

```sql theme={null}
INSERT INTO mysql_db.mysql_table VALUES (3,4)
```

```sql theme={null}
SELECT * FROM mysql_db.mysql_table
```

```text theme={null}
┌─int_id─┬─value─┐
│      1 │     2 │
│      3 │     4 │
└────────┴───────┘
```
