SQL Import & Database Errors
Database errors occur when required SQL tables are missing, table structures are outdated, or oxmysql is started in the incorrect boot order. Use this guide to resolve database issues in minutes.
1. Table 'database_name.table_name' doesn't exist
Section titled “1. Table 'database_name.table_name' doesn't exist”Error Example:
[oxmysql] ERROR: Table 'qbx_server.mtm_data' doesn't exist[script:mtm-resource] SCRIPT ERROR: @mtm-resource/server/main.lua:42: attempt to index a nil valueCause: The resource was started without executing the included database.sql or install.sql file in your MySQL/MariaDB database.
Resolution:
- Open your database administration tool (HeidiSQL, phpMyAdmin, or DBeaver).
- Select your active FiveM server database.
- Open the
database.sqlfile located in the root of the Mountain Mods resource folder. - Execute the SQL script. Verify that the required resource tables appear in your database schema.
- Restart the resource in your server console (
refreshfollowed byensure [resource-name]).
2. Unknown column 'column_name' in 'field list'
Section titled “2. Unknown column 'column_name' in 'field list'”Cause: Occurs when updating a resource from version 1.x to version 2.x without applying database schema updates, or when using a database from an older fork.
Resolution:
Execute the specific ALTER TABLE statement to add the missing column without wiping existing data:
-- Example: Adding a missing column to an existing tableALTER TABLE `mtm_settings` ADD COLUMN IF NOT EXISTS `state_data` LONGTEXT DEFAULT NULL;ALTER TABLE `mtm_logs` ADD COLUMN IF NOT EXISTS `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;3. oxmysql export not found / Attempt to index global 'MySQL' (a nil value)
Section titled “3. oxmysql export not found / Attempt to index global 'MySQL' (a nil value)”Cause:
oxmysqlis not installed or not running on your server.oxmysqlis listed after the Mountain Mods script inserver.cfg.
Resolution:
Ensure oxmysql is updated to version 2.4.0 or newer and placed near the top of your server.cfg:
# Start database connector firstensure oxmysql
# Start Mountain Mods resource after database is readyensure mtm-matrixborden4. Access denied for user 'root'@'localhost' / Connection String Errors
Section titled “4. Access denied for user 'root'@'localhost' / Connection String Errors”Cause: The database connection credentials in server.cfg are incorrect or the database server is offline.
Resolution:
Verify your mysql_connection_string format in server.cfg:
set mysql_connection_string "mysql://root:your_password@127.0.0.1/your_database_name?charset=utf8mb4"set mysql_connection_string "server=127.0.0.1;database=your_database_name;userid=root;password=your_password;charset=utf8mb4;sslmode=none"5. Duplicate Table or Primary Key Warnings (Table already exists)
Section titled “5. Duplicate Table or Primary Key Warnings (Table already exists)”If re-importing SQL files on an existing server, always ensure your scripts use CREATE TABLE IF NOT EXISTS:
CREATE TABLE IF NOT EXISTS `mtm_locations` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(100) NOT NULL DEFAULT 'Location', `coords` LONGTEXT NOT NULL, `heading` FLOAT NOT NULL DEFAULT 0, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;