> For the complete documentation index, see [llms.txt](https://docs-epc.gitbook.io/ncs-documents/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-epc.gitbook.io/ncs-documents/database-as-a-service/access-mysql-database-with-mysql-workbench.md).

# Access MySQL Database With MySQL Workbench

ตัวอย่างเบื้องต้นสำหรับการเข้าใช้งาน SQL Database ผ่าน 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="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FwbERgUxcoSmf1iqXDoao%2FScreenshot%202567-03-19%20at%2014.11.23.png?alt=media&amp;token=6bee0d08-61a4-4967-a4a5-6d9e0370f8d6" alt=""><figcaption><p>icon ของ โปรแกรม MySQL Workbench</p></figcaption></figure>

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FZq1wbIEHWAnLC462UDjB%2FScreenshot%202567-03-19%20at%2014.15.45.png?alt=media&amp;token=a4aad7a3-0920-4223-b909-a9dd6756bc06" alt=""><figcaption><p>หน้า MySQL Connections</p></figcaption></figure>

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

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2F5NJbNwcolU4QhOEz5USc%2FScreenshot%202567-03-19%20at%2014.32.43.png?alt=media&amp;token=c064a26e-e449-4728-9b6c-1f553cdc7ef5" alt=""><figcaption><p>ปุ่มเพื่อเปิดหน้าต่าง Setup New Connection</p></figcaption></figure>

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FdOSkrfga6HBEKqYAoQ0F%2FScreenshot%202567-03-19%20at%2014.35.39.png?alt=media&amp;token=84e25270-706c-4d13-ac76-0612cc1f75b9" alt=""><figcaption><p>หน้าต่าง Setup New Connection</p></figcaption></figure>

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

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2F6H8RIdrqZDqaYrWUPZy7%2FScreenshot%202567-03-19%20at%2014.56.05.png?alt=media&amp;token=126643b0-ae68-407b-abaa-8ae10fe7c6e3" alt=""><figcaption><p>กำหนด Connection Name</p></figcaption></figure>

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2F2vlSsW0yRPQf8z9kYWuq%2FScreenshot%202567-03-19%20at%2014.59.52.png?alt=media&amp;token=502705a7-1162-41f2-a3a2-a2cedb211f64" 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="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FtbuVb0PdDNiklVBFpTdG%2FScreenshot%202567-03-19%20at%2015.37.12.png?alt=media&amp;token=0fe97f66-4c62-4f71-bdf3-8cf4cac5bc6d" alt=""><figcaption><p>กรอก Hostname ของ Database</p></figcaption></figure>

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2F9gGBu6JkEoXBBMa3WlnX%2FScreenshot%202567-03-19%20at%2015.26.27.png?alt=media&amp;token=e7f36cbd-8a5f-449c-b2c8-02f104d9d33e" alt=""><figcaption><p>External IP ของ Database Instance ที่หน้า Database Instance</p></figcaption></figure>

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FvSqeJ7WlLSov77awpiSn%2FScreenshot%202567-03-19%20at%2015.43.58.png?alt=media&amp;token=79eff207-5948-448e-891a-f1839c051d34" 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="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2F7vzIYVMYeQsMQVOBvFgo%2FScreenshot%202567-03-19%20at%2015.52.06.png?alt=media&amp;token=d36a0d2b-61ac-418a-ba99-b082725712d3" 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="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2F8QbN9ULQKYvqYn5XYMN6%2FScreenshot%202567-03-19%20at%2016.03.26.png?alt=media&amp;token=46c2c05f-9d4f-4c11-a74a-d2288382fb30" alt=""><figcaption><p>แสดงรายการ Database User ของ Database Instance</p></figcaption></figure>

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

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FCFHHLjxontRT9z9A8AMW%2FScreenshot%202567-03-19%20at%2016.16.55.png?alt=media&amp;token=c359e01d-03ad-4a42-a893-85676648fa06" alt=""><figcaption><p>ปุ่ม Store in Keychain ...</p></figcaption></figure>

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FXokO0bYazTar5GwoKgLV%2FScreenshot%202567-03-19%20at%2016.44.26.png?alt=media&amp;token=391af8a0-a389-415e-b6d0-854730431adf" alt=""><figcaption><p>หน้าต่าง Store Password for Connection</p></figcaption></figure>

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FONVcYCOj6tLWAd9AUXz0%2FScreenshot%202567-03-19%20at%2016.47.12.png?alt=media&amp;token=65f7c152-ad6a-4a40-b3d3-8917ff8ef8f8" alt=""><figcaption><p>กรอก Password</p></figcaption></figure>

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

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FWlehw88jqqYxgvw44qt3%2FScreenshot%202567-03-19%20at%2016.51.30.png?alt=media&amp;token=3263d1d7-0515-4397-a44d-460366dbc9a2" alt=""><figcaption><p>ยืนยันคำสั่งสร้าง Connection</p></figcaption></figure>

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FKWmyzyosrt8wc8xMJ1FP%2FScreenshot%202567-03-19%20at%2016.54.26.png?alt=media&amp;token=64526644-e419-499c-89ec-bf073d2716c7" alt=""><figcaption><p>แสดงรายการ Connection ที่ได้ทำการสั่งสร้างไว้</p></figcaption></figure>

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

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FBKS0cVgb7ivBMxrsvboZ%2FScreenshot%202567-03-19%20at%2017.03.25.png?alt=media&amp;token=1ed18da8-1918-4d56-8616-ba1a35427899" alt=""><figcaption><p>คลิกที่ Connection ที่ทำการสร้างไว้</p></figcaption></figure>

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

<figure><img src="https://1352697161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq2BYmWTMiaonrEL8QBP2%2Fuploads%2FWolO5verkbjbKaklttko%2FScreenshot%202567-03-19%20at%2017.10.17.png?alt=media&amp;token=3c3e6fb8-3271-4fce-ba61-06b46ae6146f" alt=""><figcaption><p>แสดงหน้าต่างสำหรับจัดการ database</p></figcaption></figure>
