Docs

Connecting your database

Starting from zero? This page explains what a database is, where to get one and how to write the one line in server.cfg that connects waw-sql to it.

What you need

Your server keeps its players, money, cars and houses in a database: a separate program called MySQL or MariaDB (MariaDB is a free MySQL that works the same). waw-sql is not the database itself. It is the link between FiveM and the database, and it needs to know where the database is and how to log in. You tell it with one line in server.cfg, the mysql_connection_string.

Which of these is you?

  • You set the server up with txAdmin's ESX or QBCore recipe. txAdmin asked for your database details during setup and wrote the line for you. Open server.cfg and look for mysql_connection_string: it is already there and you don't need to change it.
  • You rent the server from a game host. Most hosts give you a database in their panel, often under "Databases" or "MySQL". It shows five things: host, port, username, password and database name. You will put those five into the line below.
  • The server runs on your own PC or VPS and there is no database yet. Install one first, as in Installing MariaDB on Windows below.

The line

Open server.cfg (in your server folder, or in txAdmin under CFG Editor) and add this line above the lines that start your resources:

server.cfg
set mysql_connection_string "mysql://root:MyPassword@127.0.0.1:3306/fivem"

Every piece of it, from left to right:

piecein the examplewhat it is
mysql://always written like this at the start
usernamerootthe database user. On your own PC this is usually root
passwordMyPasswordthat user's password, written after a :
host127.0.0.1where the database runs. 127.0.0.1 means the same machine as the FiveM server. At a host, use the address their panel shows
port3306written after a :. 3306 is the usual port; if yours is 3306 you can leave :3306 out
database namefivemwritten after a /. The database your framework's tables are in

The same line can also be written as name and value pairs. Use whichever you like; waw-sql reads both:

server.cfg
set mysql_connection_string "user=root;password=MyPassword;host=127.0.0.1;port=3306;database=fivem"

If the user has no password (a fresh XAMPP install, for example), leave the password out:

server.cfg
set mysql_connection_string "mysql://root@127.0.0.1/fivem"
Use set, never setr

setr sends a setting to every player who joins, and this line holds your database password. Always write set mysql_connection_string.

Rules that save you a headache

  • Keep the quotes around the whole value.
  • Keep only one mysql_connection_string line in server.cfg, and put it above the lines that start your resources.
  • Write 127.0.0.1 rather than localhost when the database is on the same machine. It avoids a connection problem some Windows setups have with localhost.
  • No spaces around = and ; in the pairs form: host = 127.0.0.1 does not work, host=127.0.0.1 does.
  • Write the password as it is, without changing any character into a code like %40.
  • Special characters in the password:
    • In the mysql:// form, the password can contain :, / and @, but not ?.
    • In the pairs form, it cannot contain ;.
    • If your password has both, change it to one made of letters and numbers.
  • The database must already exist. The line connects to a database; it does not create one.
  • Never share a screenshot of server.cfg or paste this line in Discord: anyone with it can log in to your database.

Installing MariaDB on Windows

Only for a server on your own PC or VPS that has no database yet.

  1. Download the MariaDB installer for Windows from mariadb.org/download (the MSI package of the latest stable version).
  2. Run it. When it asks, set a password for the root user and write it down: it goes into the line. Leave "Enable access from remote machines" unticked, tick "Use UTF8 as default server's character set", and keep the port at 3306.
  3. The installer also installs HeidiSQL, a program to look inside the database. Open it, make a new session with user root, your password and host 127.0.0.1, and connect.
  4. Right-click the connection on the left, choose Create new → Database, name it (for example fivem) and pick the collation utf8mb4_general_ci.
  5. Your framework comes with a .sql file that makes its tables (ESX and QBCore both have one). In HeidiSQL, select your new database, then use File → Run SQL file and pick that file.
  6. Write the line in server.cfg with root, your password, 127.0.0.1 and your database name.

Check that it works

Start the server and watch the console. When the line is right you will see:

Console
[waw-sql] Connected to 10.x.x-MariaDB (pool 20, 20 connections ready)

When it is not, waw-sql says why, and shows the host, port, user and database it tried (never the password). What the message means:

the console sayswhat to do
Is the MySQL/MariaDB server running and reachable at this host/port?the database program is not running, or the host or port is wrong. Start MariaDB (on Windows it is a service), then check the host and port
Username or password in mysql_connection_string is wrong.check the username and password. Mind capital letters and special characters
The database name in mysql_connection_string does not exist.the name after the / (or after database=) is misspelt, or the database was never created
The database server did not answer in time (firewall / wrong host?).the host is wrong, or a firewall blocks the port. At a game host, copy the address from their panel
the line is empty or missingthere is no set mysql_connection_string in server.cfg, or it comes after the lines that start your resources

Once it says Connected, join the game and type /sqlmenu. If the panel does not open for you, make yourself an owner as described in Who may do what.