Conexión de base de datos

Database (MySQL) setup and connection

The anti-cheat stores bans, detections and settings in a MySQL/MariaDB database. This guide covers all three scenarios: getting a database from us, installing your own, or using an existing one.

Which option fits you?

SituationRecommendation
Your FiveM server already uses MySQL (QBCore/ESX installed)Use your existing database — Option C. Simplest, no extra cost.
You have no database, or your host doesn't provide MySQLGet one from us — Option A. No setup, credentials handed to you.
You have your own server and want full controlInstall it yourself — Option B.

Option A — Get a database from us (easiest)

  1. Panel → Servers → your server → "Create Database"
  2. You'll see the credentials once — save them:
    Host    : 152.53.115.7
    Port    : 3306
    Database: tsn_42_yourserver
    User    : u42_yourserver
    Password: (28 characters, random)
  3. Add them to your FiveM server.cfg (see "Connection string" below)
Isolation guarantee: only your user can reach your database. It cannot see, list or read any other customer's database. Privileges are scoped to a single database — nothing is granted on *.*.

Your resource quota: 30 concurrent connections · 500,000 queries/hour · 200,000 writes/hour. These are far above what a normal FiveM server needs; the goal is simply to stop one customer affecting others.


Option B — Install your own

MariaDB on Debian/Ubuntu:

sudo apt update
sudo apt install -y mariadb-server
sudo mysql_secure_installation

Recommended answers during mysql_secure_installation:

QuestionAnswer
Set root password?Yes — choose a strong one
Remove anonymous users?Yes
Disallow root login remotely?Yes — root should never log in remotely
Remove test database?Yes

Then create the database and user:

sudo mysql -u root -p
CREATE DATABASE tosun_ac CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- If your FiveM server is on the SAME machine:
CREATE USER 'tosun'@'localhost' IDENTIFIED BY 'A_STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON tosun_ac.* TO 'tosun'@'localhost';

-- If your FiveM server is on a DIFFERENT machine (use its IP):
CREATE USER 'tosun'@'203.0.113.10' IDENTIFIED BY 'A_STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON tosun_ac.* TO 'tosun'@'203.0.113.10';

FLUSH PRIVILEGES;
Careful: writing 'tosun'@'%' lets the user connect from anywhere on the internet. Use your FiveM server's IP where possible. If you must use %, restrict the firewall instead.

For remote connections (FiveM and MySQL on different machines):

# /etc/mysql/mariadb.conf.d/50-server.cnf
bind-address = 0.0.0.0

# Firewall — allow ONLY your FiveM server
sudo ufw allow from 203.0.113.10 to any port 3306
sudo systemctl restart mariadb

Option C — Use your existing database

If your QBCore/ESX install already uses MySQL, nothing extra is needed. The anti-cheat adds its own tables (ts_anticheat, ac_detections, panel_*) to the same database and never touches your existing ones.

Import the schema:

mysql -u USER -p DATABASE < tosun-ac/sql/ts_anticheat.sql

Connection string — server.cfg

oxmysql accepts two formats. The URL form is short but breaks if your password contains special characters:

set mysql_connection_string "mysql://USER:PASSWORD@HOST:3306/DATABASE?charset=utf8mb4"
The most common mistake: if the password contains @, :, /, # or ?, the URL form will not work — you'll get a connection error. Use the object form below; it needs no escaping.

Object form — always safe, recommended:

set mysql_connection_string "server=HOST;port=3306;database=DATABASE;userid=USER;password=PASSWORD;charset=utf8mb4"

Example (with a database from us):

set mysql_connection_string "server=152.53.115.7;port=3306;database=tsn_42_myserver;userid=u42_myserver;password=AbC123xYz;charset=utf8mb4"
ensure oxmysql
ensure tosun-ac
ensure tosun-ac-guardian

Test the connection

Verify before starting the server:

mysql -h HOST -u USER -p DATABASE -e "SELECT VERSION();"

If it works you'll get a version number. After startup the console should show:

[oxmysql] Database server connection established

Troubleshooting

ErrorCause & fix
Access denied for userWrong password, or a special character broke the URL form. Try the object form. Confirm the user is allowed from that host.
Host 'x' is not allowed to connectThe user was created for a different IP. Check with SELECT user,host FROM mysql.user;
Connection timeoutFirewall. Test with nc -zv HOST 3306. Also check bind-address isn't 127.0.0.1.
Too many connectionsYou hit the quota (30). Usually a script is leaking connections — find it before raising the limit.
Unknown databaseDatabase name misspelled or never created.
Accented characters look brokenMake sure charset=utf8mb4 is in the connection string.

Backups

If your database is hosted by us, backups run daily and are kept for 14 days. On your own server:

mysqldump --single-transaction --quick -u USER -p DATABASE | gzip > backup-$(date +%F).sql.gz

Drop that into /etc/cron.daily/ to automate it.

Volver al inicio Tosun Dev Docs