Import a default mysql database for a server template.

Hi there,

We are trying to create a new server template and have configured everything including our needed files, the needed configuration wherever needed etc.

But we would like to import a “skeleton” database so that the default database created will use an existing database or .sql file.

Anyway to do this?


you can try something like:

mysql -u username -p -h localhost data-base-name < /path/to/data.sql

where username and data-base-name need to be replaced with variables, per haps ${USER}
or leave out the data-base-name if no variable is known.
Im not sure the variables will work though

You can make this a shell script and run it after the server is created.
Per haps someone else can shed more light on this

Sure a script would be great if it will work, thanks for the idea. :slight_smile:

Anybody have any other ideas?


I guess my next question would be, where do I add a script if I wanted to do the above suggestion?

I will start looking on my own but a nudge in the right direction would always be great :slight_smile:

A script is absolutely the right way to handle this task.

System Settings->Module Configuration->Actions upon server and user creation

Command to run after making changes to a server

The script can be anywhere on the system…you provide the full path.

You’ll need to check the ENV variables to decide when to create the database (obviously, you don’t want to create it when modifying or deleting; there’s a variable for this in the ENV for your script, along with all of the variables found in the configuration for that particular domain, including the username and database name and such).

I don’t recall off-hand what that variable is, and the online help (surprisingly and embarrassingly) doesn’t mention it. I’ll fix that shortly.

But, in the meantime, just make a script that prints the environment to a file and exits. You can then see exactly what data you have to work with, including the variable that tells you whether it’s creating, deleting, or modifying a domain.


Thank you for the help. I will post my results, though your explanation is quite self-explanatory.

Also, would it be easier, or possible to just create an “installer” package, and assign that as part of a Server Template?

System Settings -> Virtualmin Configuration -> Actions upon server and user creation - seems to be where this is found now.