Skip to content

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 value

Cause: The resource was started without executing the included database.sql or install.sql file in your MySQL/MariaDB database.

Resolution:

  1. Open your database administration tool (HeidiSQL, phpMyAdmin, or DBeaver).
  2. Select your active FiveM server database.
  3. Open the database.sql file located in the root of the Mountain Mods resource folder.
  4. Execute the SQL script. Verify that the required resource tables appear in your database schema.
  5. Restart the resource in your server console (refresh followed by ensure [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 table
ALTER 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:

  1. oxmysql is not installed or not running on your server.
  2. oxmysql is listed after the Mountain Mods script in server.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 first
ensure oxmysql
# Start Mountain Mods resource after database is ready
ensure mtm-matrixborden

4. 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"

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;