Home FiveM Setting Up a Database Connection on a FiveM Server with MySQL-Async

Setting Up a Database Connection on a FiveM Server with MySQL-Async

Last updated on Feb 13, 2025

In this tutorial, you'll learn how to integrate a MySQL database into your FiveM server using the MySQL-async resource via the Pterodactyl (VolticHost Game) panel. This setup is essential for storing persistent player data such as job records, inventories, and other roleplay information. πŸš€


πŸ“Œ Prerequisites

  • A FiveM server purchased at VolticHost.com

  • Access to the Pterodactyl panel (a.k.a. VolticHost Game Panel)

  • Basic knowledge of server administration and file management

  • A MySQL database (contact your host or use a cloud MySQL service)

  • Familiarity with FiveM resource configuration


1️⃣ First Step - Installing MySQL-Async

  1. Log in to VolticHost Game Panel.

  2. Navigate to the File Manager and then to the /resources/ directory.

  3. Upload or verify that the mysql-async resource folder is present. If it isn’t, download it from the official repository (e.g., MySQL-async GitHub) and upload it to the /resources/ folder.

βœ… MySQL-async resource is installed successfully!


2️⃣ Next Step - Configuring the Database Connection

  1. Open your server.cfg file located in the root directory using the File Manager.

  2. Add the following line to include the MySQL-async resource:

    start mysql-async
    
  3. Below that, add your database connection string. For example:

    set mysql_connection_string "server=YOUR_DB_HOST;uid=YOUR_DB_USER;password=YOUR_DB_PASSWORD;database=YOUR_DB_NAME"
    
    • Replace YOUR_DB_HOST, YOUR_DB_USER, YOUR_DB_PASSWORD, and YOUR_DB_NAME with your actual database credentials.
  4. Save the changes to your server.cfg file.

βœ… Database connection configured in server.cfg successfully!


3️⃣ Next Step - Restarting and Testing the Connection

  1. Return to the main dashboard of the VolticHost Game Panel and restart your server to apply the new configuration.

  2. Once the server is up, check the server console/logs to ensure there are no errors related to MySQL-async.

  3. (Optional) Create or use an existing resource that queries the database. For example, add a simple command in a custom resource that uses MySQL-async to retrieve data and prints it in the console:

    -- Example: In a custom server script
    RegisterCommand("testdb", function(source, args, rawCommand)
        MySQL.Async.fetchScalar('SELECT COUNT(*) FROM users', {}, function(result)
            print("Total users in the database: " .. tostring(result))
        end)
    end, false)
    
  4. Execute the command (/testdb) in-game or via the console to verify that data is being retrieved from your database.

βœ… Database connection tested and functioning correctly!


πŸŽ‰ Conclusion

You have now successfully set up a database connection on your FiveM server using MySQL-async via the Pterodactyl panel! This integration ensures that your server can store and retrieve persistent player data, which is critical for a dynamic and immersive roleplay experience. πŸš€

For more assistance, contact VolticHost Support.