# How to Set Up a MySQL Database for Your FiveM Server (/docs/fivem/database-setup)



import { Step, Steps } from 'fumadocs-ui/components/steps';

Both ESX and QBCore store player data, vehicles, jobs, and economy in a MySQL database. The standard connector is **oxmysql** (replaces the older mysql-async and ghmattimysql).

Create a Database [#create-a-database]

<Steps>
  <Step>
    Open the Databases tab [#open-the-databases-tab]

    In the [XGamingServer Panel](https://panel.xgamingserver.com), click **Databases** in the sidebar.
  </Step>

  <Step>
    Create a new database [#create-a-new-database]

    Click **New Database**. Note the generated credentials:

    * **Host** (e.g., `127.0.0.1`)
    * **Port** (e.g., `3306`)
    * **Database name**
    * **Username**
    * **Password**

    You'll need these for the connection string.
  </Step>
</Steps>

Configure oxmysql [#configure-oxmysql]

Add the connection string to your `server.cfg` (via **Files** in the sidebar):

```ini
set mysql_connection_string "mysql://dbuser:dbpassword@127.0.0.1:3306/dbname?charset=utf8mb4"
```

Alternative format (for passwords with special characters) [#alternative-format-for-passwords-with-special-characters]

If your password contains `;`, `/`, `?`, `@`, `&`, `=`, `+`, `$`, or `#`, use the semicolon format:

```ini
set mysql_connection_string "user=dbuser;password=dbpassword;host=127.0.0.1;port=3306;database=dbname"
```

Then ensure oxmysql starts **before** any framework resources:

```ini
ensure oxmysql
ensure es_extended  # or ensure qb-core
```

Import .sql Files [#import-sql-files]

Framework installation requires importing an SQL file that creates the database tables. If the txAdmin recipe handled this automatically, you can skip this step.

<Steps>
  <Step>
    Open phpMyAdmin [#open-phpmyadmin]

    From the **Databases** tab on the panel, click the phpMyAdmin link (or access it directly).
  </Step>

  <Step>
    Select your database [#select-your-database]

    Click your database name in the left sidebar.
  </Step>

  <Step>
    Import the SQL file [#import-the-sql-file]

    Click the **Import** tab. Click **Choose File** and select the `.sql` file:

    * **ESX**: `legacy.sql` (from the esx\_core download)
    * **QBCore**: `qbcore.sql` (from the txAdmin recipe)

    Click **Go** to import.
  </Step>
</Steps>

Verify the Connection [#verify-the-connection]

After starting the server, check **Console** for:

```
[oxmysql] Connected to database
```

If you see connection errors, check:

| Error                                      | Fix                                                                         |
| ------------------------------------------ | --------------------------------------------------------------------------- |
| `Access denied for user`                   | Wrong username or password in the connection string                         |
| `Unknown database`                         | Database name doesn't match — check Databases tab                           |
| `AUTH_SWITCH_PLUGIN_ERROR`                 | MySQL 8+ auth issue. Set the user to `mysql_native_password` authentication |
| `Connection refused`                       | Wrong host/port, or database server not running                             |
| Connection string with special chars fails | Switch to semicolon format                                                  |

Related Guides [#related-guides]

* [Install ESX](/docs/fivem/install-esx)
* [Install QBCore](/docs/fivem/install-qbcore)
* [Server Configuration](/docs/fivem/configure-your-server)
