Skip to content

MySQL node#

ใช้โหนด MySQL เพื่อทำงานอัตโนมัติใน MySQL และเชื่อมต่อ MySQL กับแอปพลิเคชันอื่นๆ n8n มีการสนับสนุนฟีเจอร์ของ MySQL มากมาย รวมถึงการรันคำสั่ง SQL query การเพิ่มข้อมูล และการอัปเดตแถวในฐานข้อมูล

ในหน้านี้ คุณจะพบรายการของการดำเนินการที่โหนด MySQL รองรับ และลิงก์ไปยังแหล่งข้อมูลเพิ่มเติม

Credentials

ดูที่ MySQL credentials สำหรับคำแนะนำในการตั้งค่าการยืนยันตัวตน

This node can be used as an AI tool

This node can be used to enhance the capabilities of an AI agent. When used in this way, many parameters can be set automatically, or with information directed by AI - find out more in the AI tool parameters documentation.

Operations#

  • Delete
  • Execute SQL
  • Insert
  • Insert or Update
  • Select
  • Update

Templates and examples#

Generate SQL queries from schema only - AI-powered

by Yulia

View template details
Import CSV into MySQL

by Eduard

View template details
Build an AI-Powered Tech Radar Advisor with SQL DB, RAG, and Routing Agents

by Sean Lon

View template details
Browse MySQL integration templates, or search all templates

อ้างอิงถึง MySQL's Connectors and APIs documentation สำหรับข้อมูลเพิ่มเติมเกี่ยวกับบริการนี้

อ้างอิงถึง SELECT statement documentation ของ MySQL สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการเขียนคำสั่ง SQL queries

Use query parameters#

เมื่อสร้างคำสั่ง query เพื่อรันบนฐานข้อมูล MySQL คุณสามารถใช้ฟิลด์ Query Parameters ในส่วน Options เพื่อโหลดข้อมูลเข้าไปในคำสั่ง query n8n ทำการ sanitize ข้อมูลในพารามิเตอร์ของคำสั่ง query ซึ่งช่วยป้องกันการโจมตีแบบ SQL injection

ตัวอย่างเช่น คุณต้องการค้นหาบุคคลด้วยอีเมล์ของพวกเขา จากข้อมูลนำเข้าต่อไปนี้:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[
    {
        "email": "alex@example.com",
        "name": "Alex",
        "age": 21 
    },
    {
        "email": "jamie@example.com",
        "name": "Jamie",
        "age": 33 
    }
]

คุณสามารถเขียนคำสั่ง query แบบนี้ได้:

1
SELECT * FROM $1:name WHERE email = $2;

จากนั้นใน Query Parameters ให้ระบุค่าฟิลด์ที่จะใช้ คุณสามารถใส่ค่าคงที่หรือใช้นิพจน์ (expressions) สำหรับตัวอย่างนี้ ใช้นิพจน์เพื่อให้โหนดสามารถดึงอีเมล์จากแต่ละรายการนำเข้าตามลำดับ:

1
2
// users is an example table name
users, {{ $json.email }} 

Common issues#

สำหรับข้อผิดพลาดทั่วไปหรือปัญหาและขั้นตอนการแก้ไขที่แนะนำ ดูที่ Common issues