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
| Type | Name | Description |
|---|---|---|
string | host | Hostname or IP address of the MySQL server |
string | user | MySQL user to authenticate as |
string | password | Password for the MySQL user |
string | database | Name of the database to connect to |
int | port | Port the MySQL server is listening on |
Returns
| Type | Name | Description |
|---|---|---|
database | instance | Created 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)