Automatically Create a MySQL Database

Preparing the server

  • Install the MySQL server on your server.
  • Install phpMyAdmin if you want to provide a way to manage the database.

Configure the game

Create variables

  • Configure variables for the MySQL user and password. Go to Settings > Games > Select the game > Variables. Create 2 new variables:
    • Name: MySQLUser
    • Preserve value: Checked
    • Name: MySQLPassword
    • Preserve value: Checked

Create the scripts

  • Go back to the game's main settings. Click on the Custom Scripts icon. Create the following scripts.
Operating System: Any
Description: Generate MySQL user and password
Script Engine: IronPython
Event: Before created
Ignore execution errors Unchecked
Script:
import clr;
import System;

clr.AddReference("TCAdmin.SDK");
from TCAdmin.SDK.Misc import Random;
from System import String;

ThisService.Variables["MySQLUser"] = String.Format("db{0}", ThisService.ServiceId);
ThisService.Variables["MySQLPassword"] = Random.RandomString(10,True,True);
ThisService.Save();
Retrieved from "https://help.tcadmin.com/index.php?title=Automatically_Create_a_MySQL_Database&oldid=1232"