FiveM MariaDB Remote Connection คืออะไร? วิธีให้ FXServer เชื่อม Database คนละเครื่องอย่างปลอดภัย
FiveM MariaDB Remote Connection คือการให้ FXServer และ oxmysql เชื่อมไปยัง MariaDB ที่ติดตั้งอยู่บนเครื่องอื่น แทนที่จะติดตั้ง Database ไว้เครื่องเดียวกับ FiveM Server
ตัวอย่างโครงสร้าง:
FiveM / FXServer
10.0.0.20
↓
Network
↓
MariaDB
10.0.0.30
การตั้ง Remote Database ให้ใช้งานได้ไม่ได้จบเพียงเปลี่ยน IP ใน mysql_connection_string เพราะ MariaDB ต้องถูกตั้งให้รับ TCP Connection จาก Network Interface ที่ต้องการ, Database User ต้องอนุญาต Host ต้นทาง และ Firewall ต้องอนุญาต Traffic ระหว่าง FXServer กับ Database ด้วย.
① Remote Database ต่างจาก Local Database อย่างไร
Local Database:
FXServer
↓
127.0.0.1 / localhost
↓
MariaDB
Remote Database:
FXServer
↓
Network
↓
อีกเครื่องหนึ่ง
↓
MariaDB
Remote Database จึงเพิ่ม Network Layer เข้ามา และต้องจัดการทั้ง Database Listener, Account Host และ Firewall เพิ่มจาก Local Setup.
② ทำไมบาง FiveM Server แยก Database คนละเครื่อง
เหตุผลที่อาจเลือกแยก ได้แก่:
แยก Database Workload
แยก CPU/RAM/Disk
แยก Maintenance
รองรับ Infrastructure ที่ใหญ่ขึ้น
แต่การแยกเครื่องไม่ได้ทำให้ Database เร็วขึ้นโดยอัตโนมัติ เพราะจะมี Network Latency และ Network Availability เข้ามาเกี่ยวข้องด้วย
ดังนั้น Server เล็กที่ Database Load ต่ำอาจยังเหมาะกับ Local Database ขณะที่ Server ขนาดใหญ่สามารถพิจารณาแยกตาม Workload จริง
③ oxmysql เชื่อม Remote Database ได้ไหม
ได้ เพราะ oxmysql ใช้ Connection String ที่ระบุ:
host
port
user
password
database
และ Documentation รองรับทั้ง URI Format และ Key/Value Format.
ตัวอย่าง:
set mysql_connection_string "mysql://fivem_app:PASSWORD@10.0.0.30:3306/fivem"
④ ตัวอย่าง Connection String แบบ Key/Value
set mysql_connection_string "user=fivem_app;password=PASSWORD;host=10.0.0.30;port=3306;database=fivem"
oxmysql ระบุว่าต้องตั้ง mysql_connection_string ก่อน Start Resources ที่ต้องใช้ Database และให้ใช้ set สำหรับค่านี้.
⑤ อย่าใช้ 127.0.0.1 ถ้า Database อยู่คนละเครื่อง
ถ้า Connection String ของ FXServer เป็น:
host=127.0.0.1
หมายถึง:
เครื่อง FXServer เอง
ไม่ใช่เครื่อง MariaDB อีกตัว
ดังนั้น Remote Database ต้องใช้ IP หรือ Hostname ที่ชี้ไป Database Server จริง
⑥ MariaDB ต้องเปิดรับ Remote Connection ก่อน
MariaDB Remote Client Guide ระบุว่า Server ต้องถูกตั้งให้ Listen สำหรับ Remote Connections และต้องตรวจว่า skip-networking ไม่ได้ปิด TCP Networking พร้อมตั้ง bind-address ให้เหมาะกับ Interface ที่ต้องรับ Connection.
Flow:
FXServer
↓
MariaDB IP
↓
MariaDB Listen?
↓
YES
→ ไป Authentication
NO
→ Connection ไม่ผ่าน
⑦ skip-networking คืออะไร
ถ้า MariaDB ถูกตั้งให้ปิด TCP Networking การเชื่อมจาก FXServer เครื่องอื่นจะไม่สามารถทำงานผ่าน TCP ตามปกติได้
MariaDB Remote Connection Guide จึงระบุให้ตรวจว่า:
skip-networking
ไม่ได้ถูกเปิดใช้งานสำหรับ Remote Setup.
⑧ bind-address คืออะไร
bind-address กำหนดว่า MariaDB จะ Listen บน Network Address ใด
Security Guidance ของ MariaDB แนะนำให้ Bind เฉพาะ Interface ที่ต้องการ เช่น Loopback สำหรับ Local-only หรือ Private IP ที่กำหนดสำหรับ Network-restricted Database Access.
ตัวอย่างแนวคิด:
Database Private IP
10.0.0.30
MariaDB สามารถถูกตั้งให้ Listen ที่ IP นี้ตาม Infrastructure
⑨ bind-address = 127.0.0.1 มีผลอย่างไร
ถ้า Database Listen เฉพาะ:
127.0.0.1
Remote FXServer เครื่องอื่นจะไม่สามารถเข้าถึง MariaDB ผ่าน Network Interface ภายนอกได้
นี่เหมาะกับ:
FXServer + MariaDB
อยู่เครื่องเดียวกัน
แต่ไม่เหมาะกับ Remote Database Architecture ที่ต้องรับ Connection จากอีก Host.
⑩ ควร bind ไป IP อะไร
ถ้ามี Private Network:
FXServer = 10.0.0.20
Database = 10.0.0.30
แนวทางที่จำกัดขอบเขตได้ดีกว่าคือให้ Database Listen บน Private Interface ที่ FiveM Server ใช้ติดต่อ แทนเปิด Interface มากเกินความจำเป็น
MariaDB Security Guidance แนะนำการ Bind ไปยัง Network Interface ที่เฉพาะเจาะจงเพื่อจำกัดการเข้าถึง.
⑪ ต้อง Restart MariaDB หลังแก้ bind-address ไหม
MariaDB Remote Connection Guide ระบุให้ Restart MariaDB Server หลังปรับ Server Network Configuration เช่น bind-address.
ก่อน Restart Production Database ควรมี Maintenance Plan และตรวจว่า Config ไม่มี Syntax Error
⑫ Port 3306 คืออะไร
ตัวอย่าง Connection String ของ oxmysql ใช้:
3306
เป็น Database Port ในตัวอย่าง Official Documentation.
แต่ Production Server สามารถตั้ง Port อื่นได้ ดังนั้นค่าที่ Connection String ใช้ต้องตรงกับ MariaDB Server จริง
⑬ Firewall ต้องเปิดหรือไม่
ถ้า FXServer กับ MariaDB อยู่คนละเครื่อง Network Firewall ต้องอนุญาต Traffic จาก FXServer ไปยัง Database Port ที่ใช้งานจริง
MariaDB Remote Connection Guide รวม Firewall Configuration เป็นขั้นตอนหนึ่งของ Remote Client Access.
⑭ อย่าเปิด Database ให้ทั้ง Internet ถ้าไม่จำเป็น
ถ้า Database ต้องรับ Connection จาก FiveM Server เพียงเครื่องเดียว ให้ Firewall จำกัด Source เป็น FXServer IP หรือ Private Network ที่จำเป็น
แนวคิด:
FXServer IP
✓
↓
MariaDB
Internet อื่น
✕
↓
MariaDB
MariaDB Security Guidance สนับสนุนการจำกัด Network Interfaces และ Access Scope แทนการเปิด Database กว้างเกินความจำเป็น.
⑮ Database User ต้องอนุญาต Remote Host ด้วย
MariaDB Account ไม่ได้เป็นเพียง:
username
แต่มีรูปแบบ:
'username'@'hostname'
MariaDB Remote Access Guide ระบุเรื่องนี้โดยตรง.
ตัวอย่าง:
'fivem_app'@'10.0.0.20'
หมายถึง Account ที่เชื่อมจาก FXServer IP นั้น
⑯ localhost User ใช้จาก Remote Server ได้ไหม
ถ้ามีเพียง:
'fivem_app'@'localhost'
แต่ FXServer อยู่:
10.0.0.20
Account นี้ไม่ได้หมายถึง Remote Host ดังกล่าว
จึงต้องสร้างหรือกำหนด Account ให้ Match กับ Source Host ที่ FiveM เชื่อมมาจริง.
⑰ ตัวอย่างสร้าง User สำหรับ Remote FXServer
สมมติ:
FXServer
10.0.0.20
MariaDB
10.0.0.30
สามารถออกแบบ Account:
CREATE USER
'fivem_app'@'10.0.0.20'
IDENTIFIED BY
'STRONG_PASSWORD';
MariaDB CREATE USER ใช้สร้าง Accounts และ Account ใหม่จะยังไม่มี Application Privileges จนกว่าจะ Grant เพิ่ม.
⑱ ให้ Permissions ยังไง
ตัวอย่าง Runtime CRUD:
GRANT
SELECT,
INSERT,
UPDATE,
DELETE
ON
`fivem`.*
TO
'fivem_app'@'10.0.0.20';
MariaDB ใช้ GRANT สำหรับเพิ่ม Privileges ให้ Account.
ต้องปรับ Privileges ตาม Resources จริง เพราะ Resource ที่ Auto Migration อาจต้อง Permission เพิ่ม เช่น CREATE หรือ ALTER
⑲ อย่าใช้ root Remote ถ้าไม่จำเป็น
Production FiveM ควรใช้ Dedicated Database User และจำกัด:
Host
Database
Permissions
แทนใช้ Administrative Account กว้างๆ
MariaDB Security Guidance แนะนำ Least Privilege และการจำกัด Application Account ให้เท่าที่จำเป็น.
⑳ ใช้ '%' เป็น Host ได้ไหม
MariaDB Host Patterns สามารถมี Wildcard ได้ แต่:
'fivem_app'@'%'
กว้างกว่า:
'fivem_app'@'10.0.0.20'
มาก
ถ้ารู้ Source IP ของ FXServer อยู่แล้ว การระบุ Source ให้แคบช่วยลดขอบเขตของ Account
㉑ ตรวจ Permission ด้วย SHOW GRANTS
ใช้:
SHOW GRANTS
FOR
'fivem_app'@'10.0.0.20';
MariaDB ระบุว่า SHOW GRANTS ใช้แสดง Privileges ที่ Account ได้รับ.
ทำหลังสร้าง User/GRANT เพื่อยืนยันสิทธิ์จริง
㉒ ทดสอบ Remote Login ก่อนเปิด FiveM
ก่อนแก้ Production Connection String ควรทดสอบจาก FXServer Host ว่า Database Client สามารถ Login ไปยัง MariaDB Server ได้หรือไม่
MariaDB มี Connecting Guide สำหรับเชื่อมด้วย Host, User และ Password ผ่าน Command-line Client.
Flow:
FXServer Host
↓
MariaDB Client
↓
Remote DB Login
↓
ผ่าน
↓
ค่อยตั้ง oxmysql
㉓ ถ้า Database Client ยังต่อไม่ได้ oxmysql ก็ยังไม่ใช่จุดแรกที่ต้องแก้
ถ้า Basic Remote Database Login ยังล้มเหลว ให้แก้:
MariaDB Listener
Network
Firewall
User@Host
Password
Permission
ก่อน
เพราะ oxmysql จะใช้ Network Path และ Database Authentication ชุดเดียวกันในที่สุด
㉔ Connection Refused หมายถึงอะไร
MariaDB Troubleshooting Guide ระบุว่าเมื่อ Network Test ได้ข้อความ Connection refused สาเหตุอาจเกี่ยวกับ Network/Firewall หรือ MariaDB ไม่ได้ Listen บน TCP/IP Interface/Port ที่ทดสอบ.
ดังนั้นให้ตรวจ:
MariaDB Running?
↓
Listen Address?
↓
Port?
↓
Firewall?
㉕ Connection Refused ไม่ใช่ Password Error
ถ้า TCP Connection ยังถูกปฏิเสธ Authentication อาจยังไม่ได้เกิดขึ้น
จึงไม่ควรเปลี่ยน Database Password ซ้ำๆ หาก Error จริงอยู่ที่ Network Listener
㉖ Access Denied ต่างจาก Connection Refused
Connection Refused
ยังไปไม่ถึง Authentication อย่างถูกต้อง
Access Denied
Database ตอบแล้ว
แต่ User/Host/Auth/Permission ไม่ผ่าน
MariaDB Account และ Privilege System ใช้ User+Host ในการระบุ Account ที่ Authenticate.
㉗ CURRENT_USER() ช่วย Debug ได้อย่างไร
MariaDB CURRENT_USER() แสดง User และ Host Combination ที่ Server ใช้ Authenticate Client จริง.
ตัวอย่าง:
SELECT CURRENT_USER();
ช่วยตรวจได้ว่า Database Match Account ไหน
㉘ Hostname หรือ IP ใช้อะไรดีกว่า
ทั้งสองใช้ได้ตาม Infrastructure แต่ต้องคิดเรื่อง:
DNS Availability
IP Stability
Network Routing
Firewall Rules
สำหรับ Private Infrastructure ที่ IP คงที่ การใช้ Private IP สามารถทำให้ Flow ตรงไปตรงมา
ถ้าใช้ Hostname ต้องมั่นใจว่า FXServer Resolve DNS ได้เสถียร
㉙ อย่าใช้ Public IP ถ้ามี Private Network ให้ใช้
ถ้า VPS/Cloud มี Private Network ระหว่าง:
FXServer
↔
MariaDB
การใช้ Private Network ช่วยไม่ต้องส่ง Database Traffic ผ่าน Public Internet โดยไม่จำเป็น
Database Firewall ยังควรอนุญาตเฉพาะ Source ที่ต้องใช้
㉚ Remote Database เพิ่ม Ping ให้ FiveM Player ไหม
ไม่ใช่ Player Ping โดยตรง
แต่ Database Network Latency สามารถเพิ่มเวลาของ Operations ที่ Resource ต้องรอ Database เช่น:
Character Load
Vehicle Query
Save
Admin Search
ดังนั้น Database Server ควรอยู่ Network/Region ที่มี Latency ต่ำและเสถียรเมื่อ FiveM ต้อง Query บ่อย
㉛ Database อยู่คนละประเทศควรไหม
โดยทั่วไปไม่เหมาะกับ Hot-path Database Workload หากเพิ่ม Network Latency มากโดยไม่มีเหตุผล
ตัวอย่าง:
FXServer Thailand
↓
Database Europe
อาจเพิ่ม Database Round-trip Time
ถ้าแยกเครื่อง ควรให้ Network ระหว่างสองเครื่องใกล้และเสถียรเท่าที่ Architecture อนุญาต
㉜ Network Latency กับ Slow Query ต่างกัน
Resource อาจเห็น Operation ช้าเพราะ:
Database Execution
+
Network Delay
ดังนั้น Slow Database Response บน Remote Setup ต้องตรวจทั้ง:
SQL
Index
Database CPU
Network Latency
ไม่ใช่ SQL อย่างเดียว
oxmysql ระบุว่า Query Performance สามารถได้รับผลจาก Environment และ Current Workload และมี Debug Tools สำหรับดู Query Timing.
㉝ เปิด mysql_debug ช่วยอะไร
oxmysql รองรับ:
set mysql_debug true
เพื่อ Print Queries ใน Server Console และยังสามารถ Debug เฉพาะ Resources ได้.
เหมาะเมื่อ Connection ผ่านแล้วแต่สงสัยว่า Remote Database ทำให้ Query ช้าหรือ Resource Query มากเกินไป
㉞ mysql_debug ไม่ได้แก้ Connection Refused
ถ้า oxmysql ยังต่อ Database ไม่ได้ Debug Query ก็ไม่ได้มี Query ที่ Execute สำเร็จให้วิเคราะห์
ให้แก้:
Listener
Firewall
User
Connection String
ก่อน
㉟ Password มี @ หรือ : ต้องระวัง
oxmysql ระบุว่า Connection String บาง Format มี Special Characters ที่ Reserved หรือไม่รองรับ และแนะนำให้ลองเปลี่ยน Connection String Format.
ถ้า URI มีปัญหา:
mysql://user:PASSWORD@host/database
สามารถลอง Key/Value Format:
user=user;password=PASSWORD;host=10.0.0.30;port=3306;database=fivem
㊱ อย่าแชร์ Remote Database Connection String
Remote Connection String สามารถเปิดเผย:
Database Host
Username
Password
Database Name
Port
จึงไม่ควรโพสต์ Config จริงลง Public Forum หรือ Screenshot โดยไม่ Mask Secrets
㊲ Resource Start Order ยังสำคัญไหม
สำคัญเหมือน Local Database
oxmysql Documentation ระบุให้:
start oxmysql
อยู่ต้น Resource List และตั้ง Connection String ก่อน Start Resources.
ตัวอย่าง:
set mysql_connection_string "..."
ensure oxmysql
ensure framework
ensure my_resource
㊳ Database ต้องพร้อมก่อน FXServer Start ไหม
ควรให้ Infrastructure จัดลำดับให้ MariaDB พร้อมรับ Connectionก่อน oxmysql/Resources ที่ต้อง Query
ถ้า Database กำลัง Restart ขณะที่ FXServer Start อาจเกิด Initial Connection Failures
โดยเฉพาะระบบที่ Auto Restart ทั้งสอง Services พร้อมกัน
㊴ Remote Database ล่ม FiveM จะเป็นอะไร
Resources ที่พึ่ง Database อาจไม่สามารถ:
Load Persistent Data
Save Data
Query Character
Query Vehicle
ได้ตามปกติ
ผลกระทบขึ้นกับ Framework และ Error Handling ของ Resource
ดังนั้น Database Availability กลายเป็น Dependency สำคัญของ FiveM Server
㊵ Network หลุดชั่วคราวมีผลไหม
มี
Remote Database เพิ่ม Failure Mode:
FXServer ปกติ
MariaDB ปกติ
แต่ Network ระหว่างกลางมีปัญหา
Database Operations ก็สามารถล้มเหลวได้
Local Database ไม่มี Network Hop ภายนอกแบบเดียวกัน
㊶ Remote Database มีข้อดีข้อเสียอะไร
ข้อดี
แยก Database Workload
แยก Maintenance
แยก Storage
Scale Infrastructure ได้ง่ายขึ้นในบางระบบ
ข้อเสีย
เพิ่ม Network Latency
เพิ่ม Firewall Configuration
เพิ่ม Failure Point
เพิ่ม Security Configuration
เพิ่ม Operational Complexity
จึงไม่ควรแยก Database เพียงเพราะคิดว่า “Server ใหญ่ต้องแยกเสมอ”
㊷ Remote Database กับ Backup
แม้ Database อยู่คนละเครื่องก็ยังต้อง Backup
การแยก Machine ไม่ได้เท่ากับ Backup
ถ้า MariaDB Data ถูกลบผิด:
Remote Server
ก็ยังเก็บ Data ที่ถูกลบผิดเหมือนเดิม
Backup ต้องเป็นอีก Recovery Mechanism
㊸ Remote Database กับ Replication ต่างกัน
Remote Database:
FiveM ใช้ Database ที่อยู่คนละเครื่อง
Replication:
Database หลาย Instance
มีการ Replicate Data
เป็นคนละเรื่อง
MariaDB มีระบบ Primary/Replica Replication แยกต่างหากสำหรับ Architecture ที่ต้องการ Replication.
㊹ ต้องทำ Replication สำหรับ FiveM ไหม
ไม่จำเป็นสำหรับ Server ทั่วไป
Replication เพิ่ม:
Configuration
Monitoring
Failover Planning
Consistency Considerations
จึงควรทำเมื่อ Requirement ด้าน Availability/Scale มีจริง
Remote Database เครื่องเดียวไม่จำเป็นต้องมี Replica เพียงเพื่อให้ oxmysql ใช้งานได้
㊺ Remote Database กับ Connection Pool
oxmysql ใช้ Database Driver จัด Connections ให้ Resource
แต่ Connection Pool ไม่ได้แก้:
Firewall Block
Wrong Host
MariaDB ไม่ Listen
Wrong User@Host
Connection Infrastructure ต้องผ่านก่อน Pool จะช่วยจัด Database Operations ได้
㊻ Remote Database กับ Query Count
ถ้า Resource ทำ:
20 Queries ต่อ Action
Remote Network Round Trips ยิ่งมีผลมากขึ้น
ดังนั้นเมื่อใช้ Remote Database ยิ่งควร:
ลด Query ที่ไม่จำเป็น
ใช้ Cache
แก้ N+1 Queries
ใช้ Upsert ตาม Use Case
ก่อนเพิ่ม Hardware อย่างเดียว
㊼ Remote Database กับ Cache
ตัวอย่าง Architecture:
Player Login
↓
Remote Database
↓
Load Settings
↓
Cache
Gameplay
↓
ใช้ Cache
แทน:
ทุก Gameplay Action
↓
Remote Database
ช่วยลด Network + Database Round Trips ที่ไม่จำเป็น
㊽ Remote Database กับ Autosave
ระวัง Autosave ทุก Player พร้อมกัน
ตัวอย่าง:
200 Players
↓
ทุก 5 นาที
↓
Save พร้อมกัน
จะสร้างทั้ง:
Network Burst
Database Write Burst
ควรพิจารณา Dirty Flag และกระจาย Save ตาม Architecture
㊾ วิธี Test Remote Connection ก่อน Production
ใช้ Checklist:
① MariaDB Running
② MariaDB Listen บน Interface ถูก
③ skip-networking ไม่ Block TCP
④ Firewall Allow FXServer
⑤ Database User@Host ถูก
⑥ SHOW GRANTS ถูก
⑦ Login จาก FXServer Host ได้
⑧ Database Name ถูก
⑨ oxmysql Connection String ถูก
⑩ Start oxmysql
⑪ Test SELECT
⑫ Test INSERT/UPDATE ใน Test Environment
MariaDB Remote Access Guide ระบุองค์ประกอบหลักคือ Network Listener, Remote User Privileges และ Firewall.
㊿ วิธีแก้ Remote Database ต่อไม่ได้แบบเร็ว
ใช้ลำดับ:
MariaDB Running?
↓
Local Login ได้?
↓
MariaDB Listen TCP?
↓
bind-address ถูก?
↓
Firewall ผ่าน?
↓
User@Host มี?
↓
Password ถูก?
↓
Privileges ถูก?
↓
oxmysql Host/Port ถูก?
อย่าเปลี่ยนหลายค่าในครั้งเดียว เพราะจะไม่รู้ว่าสาเหตุจริงคืออะไร
51. Local ต่อได้ แต่ Remote ต่อไม่ได้
นี่เป็นสัญญาณให้ตรวจ:
bind-address
skip-networking
Firewall
User@Host
MariaDB Troubleshooting และ Remote Client Guides ระบุจุดเหล่านี้เป็นองค์ประกอบหลักของ Remote Connection.
52. Remote ต่อได้แต่ oxmysql ต่อไม่ได้
ถ้า Database Client จาก FXServer Host Login ได้ แต่ oxmysql ไม่ได้ ให้ตรวจ:
mysql_connection_string
Database Name
Special Characters
Start Order
oxmysql Console Error
oxmysql ระบุ Connection String Formats, Special Character Caveats และ Start Order ไว้ใน Setup Documentation.
53. Remote ต่อได้แต่ Query Error
แปลว่า Network/Authentication อาจผ่านแล้ว
ตรวจต่อ:
Table
Column
Migration
Permissions
SQL Syntax
อย่ากลับไปแก้ Firewall ถ้า Error จริงคือ:
Unknown column
54. Access Denied หลังย้าย FXServer
ถ้า FXServer เดิม:
10.0.0.20
แล้วเครื่องใหม่:
10.0.0.25
Database Account เดิม:
'fivem_app'@'10.0.0.20'
อาจไม่ Match Source ใหม่
MariaDB Accounts ใช้ Username+Host เป็นส่วนของ Account Identity.
55. Database IP เปลี่ยนต้องแก้อะไร
ตรวจ:
mysql_connection_string
Firewall Destination
DNS
Monitoring
Backup Scripts
ถ้าใช้ Hostname ที่ Update DNS ถูกต้องอาจไม่ต้องแก้ Connection String แต่ต้องตรวจ DNS Resolution จาก FXServer
56. Remote Database Security Checklist
ก่อน Production:
Database ใช้ Private Network เมื่อทำได้
MariaDB Bind เฉพาะ Interface ที่ต้องการ
skip-networkingถูกตั้งตาม RequirementFirewall รับเฉพาะ FXServer Source
Database User แยกจาก root
User Host จำกัด
Database Scope จำกัด
Permissions จำกัด
Password แข็งแรง
Connection String ไม่ถูกแชร์
Password ไม่อยู่ใน client.lua
SHOW GRANTSถูกตรวจRemote Login ถูก Test
Backup มี
Restore ถูกทดสอบ
Database Monitoring มี
Slow Query Monitoring มี
Network Latency ถูกวัด
Autosave Burst ถูกตรวจ
Database อยู่ Region ใกล้ FXServer
ตารางปัญหา FiveM Remote Database
| อาการ | จุดที่ควรตรวจ |
|---|---|
| Local ได้ Remote ไม่ได้ | bind-address / Firewall / User@Host |
| Connection Refused | MariaDB Listener / Port / Firewall |
| Access Denied | Username / Password / Host Matching |
| Unknown Database | Connection String Database Name |
| oxmysql ต่อไม่ได้ | Connection String / Start Order |
| Query ช้า | Network + SQL + Index |
| หลุดเป็นช่วงๆ | Network / DB Availability |
| หลังย้าย VPS ใช้ไม่ได้ | Source IP / User@Host / Firewall |
MariaDB Troubleshooting Guide ระบุว่า Connection refused เชื่อมโยงกับ Network/Firewall หรือ Server ไม่ได้ Listen บน TCP/IP Interface/Port ที่ต้องการ.
FiveM Database อยู่คนละเครื่องได้ไหม
ได้
oxmysql Connection String สามารถระบุ Remote Host แทน localhost ได้ และ MariaDB สามารถถูกตั้งให้รับ Remote Client เมื่อ Network Listener, User Privileges และ Firewall ถูกตั้งอย่างเหมาะสม.
FiveM Remote Database ตั้ง Host ยังไง
ถ้า MariaDB IP คือ:
10.0.0.30
ตัวอย่าง:
set mysql_connection_string "user=fivem_app;password=PASSWORD;host=10.0.0.30;port=3306;database=fivem"
oxmysql รองรับ Connection String รูปแบบนี้.
FiveM MariaDB bind-address ตั้งยังไง
ต้องตั้งให้ MariaDB Listen บน Interface ที่ Remote FXServer สามารถเข้าถึงได้ โดย MariaDB Remote Connection Guide ระบุให้ตรวจ bind-address และ skip-networking.
เพื่อความปลอดภัยควรใช้ Network Interface ที่เฉพาะเจาะจงตาม Infrastructure แทนเปิดกว้างโดยไม่จำเป็น.
FiveM Remote Database ต้องเปิด Port 3306 ไหม
ต้องอนุญาต Database Port ที่ MariaDB ใช้งานจริงผ่าน Firewall ระหว่าง FXServer กับ Database
MariaDB Guide ใช้ 3306 ในตัวอย่าง Remote Connectivity/Firewall แต่ Production ต้องตรวจ Port จริงของ Database Server.
FiveM Database Connection Refused แก้อย่างไร
ตรวจ:
MariaDB Service
↓
bind-address
↓
skip-networking
↓
Port
↓
Firewall
MariaDB ระบุว่า Connection Refused จากการทดสอบ Network สามารถหมายถึง Firewall/Network Problem หรือ MariaDB ไม่ได้ Listen บน Interface/Port นั้น.
FiveM Database Access Denied หลังแยกเครื่อง
ตรวจ:
'fivem_app'@'HOST'
ให้ Match กับ Source Host ของ FXServer เพราะ MariaDB Account ระบุทั้ง Username และ Host.
FiveM Remote Database ใช้ root ได้ไหม
ทำได้ในเชิงเทคนิคหาก Database Configuration อนุญาต แต่ Production ควรใช้ Dedicated Application User ที่ถูกจำกัด Host/Database/Privileges ตามหลัก Least Privilege.
FiveM Remote Database ทำให้ Server Lag ไหม
ไม่จำเป็นต้อง Lag แต่เพิ่ม Network Layer ระหว่าง FXServer กับ Database
ถ้า Latency สูงหรือ Query จำนวนมาก Database Operations อาจตอบช้าลง
ดังนั้นต้องวัดทั้ง Query Timing และ Network Latency ไม่ควรสรุปจากคำว่า Remote อย่างเดียว
FiveM Database ควรอยู่เครื่องเดียวหรือแยก
ไม่มีคำตอบเดียว
อยู่เครื่องเดียว
เหมาะเมื่อ:
Setup ต้องการความง่าย
Database Load ไม่สูง
เครื่องมี CPU/RAM/Disk เพียงพอ
แยกเครื่อง
เหมาะเมื่อ:
ต้องการแยก Workload
ต้องการแยก Maintenance
มี Infrastructure รองรับ
Network ระหว่างเครื่องเร็วและเสถียร
เลือกจาก Monitoring จริง ไม่ใช่จำนวนผู้เล่นเพียงอย่างเดียว
FAQ FiveM MariaDB Remote Connection
FiveM ใช้ MariaDB คนละเครื่องได้ไหม
ได้ โดยต้องตั้ง MariaDB ให้รับ Remote Connections พร้อม User Privileges และ Firewall ที่ถูกต้อง.
oxmysql ตั้ง Remote Host ได้ไหม
ได้ โดยกำหนด Host ใน mysql_connection_string.
bind-address คืออะไร
เป็น Configuration ที่กำหนด Network Interface ที่ MariaDB Listen และ MariaDB Security Guidance แนะนำให้จำกัด Interface ตามความจำเป็น.
skip-networking คืออะไร
เป็น Configuration ที่เกี่ยวข้องกับ TCP Networking และ MariaDB Remote Connection Guide ระบุให้ตรวจว่าไม่ได้ปิด Network Access ใน Remote Setup.
User@Host สำคัญไหม
สำคัญ MariaDB Account ใช้ทั้ง Username และ Host เป็นส่วนของ Identity.
fivem_app@localhost ใช้จาก VPS อื่นได้ไหม
ไม่ควรคาดหวังว่าจะ Match Remote VPS เพราะ Host ของ Account ไม่ตรงกับ Source Remote Host
ใช้ % เป็น Host ดีไหม
กว้างกว่าการระบุ FXServer IP โดยตรง หากทราบ Source Host ควรจำกัดให้แคบเท่าที่ Infrastructure รองรับ
Remote Database ต้องเปิด Firewall ไหม
ต้องอนุญาต Traffic จาก FXServer ไปยัง Database Port ที่ใช้งานจริง และ MariaDB Remote Access Guide รวม Firewall เป็นส่วนหนึ่งของ Configuration.
Connection Refused หมายถึงอะไร
อาจเกี่ยวกับ Firewall/Network หรือ MariaDB ไม่ได้ Listen บน TCP/IP Interface/Port นั้น.
Remote Database ทำให้ Ping ผู้เล่นสูงไหม
ไม่ใช่ Player Ping โดยตรง แต่ Network Latency ระหว่าง FXServer กับ Databaseสามารถเพิ่มเวลาของ Database-dependent Operations
Remote Database ต้องใช้ root ไหม
ไม่ ควรใช้ Dedicated User ที่มีสิทธิ์เฉพาะที่จำเป็นใน Production.
เช็ก Permission ของ Remote User ยังไง
ใช้:
SHOW GRANTS
FOR 'fivem_app'@'10.0.0.20';
MariaDB รองรับ SHOW GRANTS สำหรับดู Privileges ของ Account.
ประเด็นสำคัญ
FiveM Remote Database จะทำงานได้เมื่อ 4 ชั้น ตรงกัน:
① MariaDB Listen
② Network / Firewall ผ่าน
③ User@Host + Permission ถูก
④ oxmysql Connection String ถูก
MariaDB Remote Client Guide ระบุชัดว่าการเปิด Remote Connection ต้องดู Server Network Configuration, Remote User Privileges และ Firewall ร่วมกัน ไม่ใช่เปลี่ยน Host ใน Connection String เพียงอย่างเดียว.
ถ้า Local Connection ใช้ได้แต่ Remote ใช้ไม่ได้ ให้เริ่มจาก:
bind-address
skip-networking
Firewall
User@Host
และถ้า Network Test ขึ้น Connection refused MariaDB ระบุว่าให้สงสัย Network/Firewall หรือ Server ไม่ได้ Listen บน Interface/Port นั้นก่อน.
เมื่อ Network และ Authentication ผ่านแล้วจึงตั้ง:
set mysql_connection_string "..."
ใน FiveM และให้ oxmysql Start ก่อน Resources ที่ต้องใช้ Database ตาม Official oxmysql Configuration.
สำหรับผู้อ่าน comsiam ให้จำสูตร “Listen → Firewall → User@Host → oxmysql” และ comsiam แนะนำว่า Remote Database ที่ดีไม่ใช่ Database ที่ “เปิดให้ต่อจากไหนก็ได้” แต่คือ Database ที่เปิดเฉพาะ Network Path, Host และ Privileges ที่ FiveM Server ต้องใช้จริง พร้อม Backup และ Monitoring ที่ตรวจสอบได้
Comments
Post a Comment