# Access MySQL Database With MySQL Workbench

## Prerequisite

* มี MySQL database instance สำหรับการใช้งาน MySQL database ([ขั้นตอนการสร้าง MySQL Database Instance](/ncs-documents/database-as-a-service/sql-database/create-sql-database-instance/create-mysql-database-instance.md))
* มีโปรแกรมสำหรับเข้าถึง MySQL database เช่น MySQL Workbench (ดาวน์โหลดได้ที่ <https://dev.mysql.com/downloads/workbench/>)
* มี database user สำหรับเข้าถึง MySQL database ([ขั้นตอนการจัดการ Database User](/ncs-documents/database-as-a-service/sql-database/manage-sql-database-user.md))

## Instruction

วิธีเข้าถึง MySQL database ด้วย MySQL Workbench มีดังนี้

### 1. เปิดโปรแกรม MySQL Workbench

ดับเบิลคลิกที่ icon ดังรูป เพื่อเปิดโปรแกรม MySQL Workbench

<figure><img src="/files/prV1BtBLYU96crIcgmpK" alt=""><figcaption><p>icon ของ โปรแกรม MySQL Workbench</p></figcaption></figure>

จะปรากฎหน้า MySQL Connections เป็นหน้าเริ่มต้น ดังนี้

<figure><img src="/files/kqtgbCgZxugR9AmiQv2k" alt=""><figcaption><p>หน้า MySQL Connections</p></figcaption></figure>

### 2. สร้าง Connection เพื่อเข้าถึง Database

#### 2.1 คลิกเครื่องหมายบวก (+) ข้างหัวข้อ MySQL Connections ดังภาพ เพื่อเปิดหน้าต่าง Setup New Connection

<figure><img src="/files/RzP8gg2nVD6ILhVrggHw" alt=""><figcaption><p>ปุ่มเพื่อเปิดหน้าต่าง Setup New Connection</p></figcaption></figure>

จะปรากฎหน้าต่าง Setup New Connection ดังนี้

<figure><img src="/files/9z0dulIqi62xSQkBGMDd" alt=""><figcaption><p>หน้าต่าง Setup New Connection</p></figcaption></figure>

#### 2.2 กำหนด Connection Name&#x20;

ระบุชื่อของ connection นี้ ที่ช่อง Connection Name&#x20;

<figure><img src="/files/JkinuediTigtv9TMaXRC" alt=""><figcaption><p>กำหนด Connection Name</p></figcaption></figure>

#### 2.3 กำหนด Connection Method เป็น Standard (TCP/IP)

<figure><img src="/files/ttPqL3cAu4E3PlGF2rrS" alt=""><figcaption><p>เลือก Standard (TCP/IP)</p></figcaption></figure>

#### 2.4 กรอก Hostname ของ Database&#x20;

กรอก Hostname ของ database ซึ่งเป็นเลข external IP ของ database instance โดยดูได้จาก หน้า database instance และ database instance detail&#x20;

<figure><img src="/files/4eCzPqRh2tWcSgC53REc" alt=""><figcaption><p>กรอก Hostname ของ Database</p></figcaption></figure>

<figure><img src="/files/y5DNVZxw4tDMumHFMVk2" alt=""><figcaption><p>External IP ของ Database Instance ที่หน้า Database Instance</p></figcaption></figure>

<figure><img src="/files/xE1Pog7kh6w3sraceF2d" alt=""><figcaption><p>External IP ของ Database Instance ที่หน้า Database Instance Detail</p></figcaption></figure>

#### 2.5 กรอก Username&#x20;

กรอก username ของ database user ที่จะใช้เข้าถึง database โดย host ที่จะเข้าถึง ต้องมีเงื่อนไขตรงตามขอบเขตการเข้าถึงของ database นั้น ๆ ที่กำหนดไว้

<figure><img src="/files/Cwmbn09TfTsddocnlYfq" alt=""><figcaption><p>กรอก Username </p></figcaption></figure>

{% hint style="info" %}
กรณีเชื่อมต่อกับ database ที่สร้างบน NCS สามารถดูรายการ database user และเงื่อนไขการเข้าถึง (allowed hosted) ได้ที่หน้า Database Instance Detail > Access Management ดังภาพ
{% endhint %}

<figure><img src="/files/jm52tPfKXPNPrKVoIp3V" alt=""><figcaption><p>แสดงรายการ Database User ของ Database Instance</p></figcaption></figure>

#### 2.6 กรอก Password&#x20;

คลิกที่ปุ่ม 'Store in Keychain ...' จากนั้น จะปรากฏหน้าต่าง Store Password for Connection ขึ้นมา

<figure><img src="/files/HaOFKy59PZljocjFi2p7" alt=""><figcaption><p>ปุ่ม Store in Keychain ...</p></figcaption></figure>

<figure><img src="/files/WVQ6WRTYnmT3rmEx7N8N" alt=""><figcaption><p>หน้าต่าง Store Password for Connection</p></figcaption></figure>

กรอก password ของ database user ที่กำหนดไว้ แล้วคลิก OK เพื่อยืนยัน

<figure><img src="/files/abiUTEcqROOHuevfv54Q" alt=""><figcaption><p>กรอก Password</p></figcaption></figure>

#### 2.7 ยืนยันคำสั่งสร้าง Connection

คลิกปุ่ม OK เพื่อยืนยันคำสั่งสร้าง connection

<figure><img src="/files/ajqNz9RxBEDtriAfJ94Y" alt=""><figcaption><p>ยืนยันคำสั่งสร้าง Connection</p></figcaption></figure>

เมื่อสร้างสำเร็จ จะปรากฏรายการ connection ที่หน้า MySQL Connections ดังนี้

<figure><img src="/files/Yc7qdLFJCkrWFJi008no" alt=""><figcaption><p>แสดงรายการ Connection ที่ได้ทำการสั่งสร้างไว้</p></figcaption></figure>

### 3. คลิกที่ Connection เพื่อเข้าถึง Database

คลิกที่ connection เพื่อเข้าสู่ MySQL database&#x20;

<figure><img src="/files/f5KY3JeJMHw8GPlBuhOO" alt=""><figcaption><p>คลิกที่ Connection ที่ทำการสร้างไว้</p></figcaption></figure>

เมื่อคลิกแล้ว จะปรากฏหน้าต่าง SQL editor ขึ้นดังภาพ แสดงว่าเข้าถึง MySQL database ได้สำเร็จ

<figure><img src="/files/m0fWyMcpWGHkhOshzIHX" alt=""><figcaption><p>แสดงหน้าต่างสำหรับจัดการ database</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-epc.gitbook.io/ncs-documents/database-as-a-service/access-mysql-database-with-mysql-workbench.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
