Vital.sandbox
Database

database.create

Server

Creates a new database instance and establishes a MySQL connection


Syntax

local instance = database.create(host, user, password, database, port = 3306)

The password argument is always required. Refer below for how to pass it depending on your setup.

  • With password — pass the password as a string, e.g. "secret"
  • Without password — pass "" as the value

Parameters

TypeNameDescription
stringhostHostname or IP address of the MySQL server
stringuserMySQL user to authenticate as
stringpasswordPassword for the MySQL user
stringdatabaseName of the database to connect to
intportPort the MySQL server is listening on

Returns

TypeNameDescription
databaseinstanceCreated database instance

Examples

local db = database.create("127.0.0.1", "root", "", "vital_sandbox")

local db = database.create("127.0.0.1", "root", "secret", "vital_sandbox", 3307)

On this page