Database

oxmysql cannot connect to the database

The database is not running, the connection string is wrong, or it is set after oxmysql starts.

The error
[oxmysql] Unable to establish a connection to the database (ECONNREFUSED / ER_ACCESS_DENIED_ERROR)

What the code means

  • ECONNREFUSED: MySQL or MariaDB is not running, or uses a different port.
  • ER_ACCESS_DENIED_ERROR: wrong user name or password.
  • ER_BAD_DB_ERROR: the database name does not exist.
  • Unknown column or Table doesn't exist: a resource's SQL file was never imported.

How to fix it

  1. Put the connection string above ensure oxmysql in server.cfg:
Config
set mysql_connection_string "mysql://fivem:[email protected]:3306/fivem?charset=utf8mb4"
ensure oxmysql
  1. Make sure the database service is running and the database exists.
  2. If the password has special characters such as @, # or /, URL encode them (@ becomes %40).
  3. Import the .sql file that comes with each resource before starting it.