Install oxmysql on RedM
oxmysql is the MySQL driver most RedM frameworks and scripts use. It must be installed from a release build, configured with one convar, and started before anything that touches the database.
Before you start
- A MySQL or MariaDB server reachable from the game server
- A database and a user with rights on it
Install steps
Step 1: Download the release build
Take the archive from the oxmysql GitHub releases page, not the green "Code" download: the repository source must be built first, the release is ready to run. Extract it so you get
resources/oxmysql/fxmanifest.lua.Step 2: Create the database
If your framework does not create it for you, create an empty database with a utf8mb4 charset and a user for the server.
CREATE DATABASE redm CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'redm'@'localhost' IDENTIFIED BY 'change-me'; GRANT ALL PRIVILEGES ON redm.* TO 'redm'@'localhost';Step 3: Set the connection string
Add the convar to
server.cfgwithset(notsetr), beforeensure oxmysql. The URI form is the most common. Characters such as; , / ? : @ & = + $ #in the password can break the string: avoid them, or use the key-value form instead.set mysql_connection_string "mysql://redm:change-me@localhost:3306/redm"Step 4: Ensure it first
oxmysql goes before the framework and before every script that imports
@oxmysql/lib/MySQL.lua.ensure oxmysql # framework and scripts belowStep 5: Check the connection
On start, oxmysql logs whether it connected. Fix any error there before installing scripts that use the database.
Troubleshooting
ECONNREFUSED
The database server is not running, or the host and port are wrong. On a separate machine, use its address instead of localhost.
Access denied for user
Wrong user or password, or the user was created for another host ('redm'@'localhost' cannot connect from another machine).
Unknown database
The database name at the end of the URI does not exist. Create it, or fix the name.
Scripts fail with MySQL errors at boot
They start before oxmysql. Move ensure oxmysql to the top.
FAQ
MySQL or MariaDB?
Both can be used. The oxmysql docs recommend MariaDB for compatibility, so pick it when your host gives you the choice.
Is there another connection string format?
oxmysql also accepts a key-value form such as user=redm;password=change-me;host=localhost;port=3306;database=redm.
Do The Lab scripts need oxmysql?
The Lab Id and The Lab Telegram do. The Lab Hud and The Lab Devtools do not use a database.
Related guides
- RedM server.cfg ensure orderWhy start order matters in a RedM server.cfg and the order that works: database, libraries, framework core, inventory, then your scripts.
- How to install a RedM scriptInstall any RedM resource: get the files, check fxmanifest dependencies, add SQL and items, place the ensure line and test from the console.
- Set up a RedM server with txAdminCreate a RedM server with txAdmin: FXServer artifacts, Cfx.re license key, gamename rdr3, OneSync and a deployment for your framework.