Database conflicts between production and sandbox Mdl?

Database conflicts between production and sandbox Mdl?

by Bob Heckmann -
Number of replies: 3

I'm running Moodle 3.1 in production and want to install the same version in another directory as a sandbox (my server is hosted by a third party, Inmotionhosting). 

I'm not terribly experienced with databases and have a question. I plan to use the config.php from production, which includes the settings listed below, in the sandbox. Do I need to use different values for 'dbname' and/or 'dbuser' in order to avoid conflict with the production database? Does using a different 'dbname' cause the server to create a new set of tables with that name that will be unique to the sandbox instance?

Thanks in advance for the assistance!

$CFG->dbtype    = 'mysqli';

$CFG->dblibrary = 'native';

$CFG->dbhost    = 'localhost';

$CFG->dbname    = 'my_db_mood910';

$CFG->dbuser    = '********';

$CFG->dbpass    = '********';

$CFG->prefix    = 'mdl_';

$CFG->dboptions = array (

  'dbpersist' => 0,

  'dbsocket' => 0,

);

(Edited by Helen Foster to remove username and password - original submission Sunday, 11 December 2016, 2:15 AM)

Average of ratings: -
In reply to Bob Heckmann

Re: Database conflicts between production and sandbox Mdl?

by Randy Thornton -
Picture of Documentation writers


Bob,

Yes, you should use a different database for each instance, each with its own db user.

(Otherwise they will be the same instance and write all over each other in the same database which will create chaos. Now, while in theory you could use the same db but a distinct table prefix, but I would never do this in real life in a production instance. It is much better - safer, more secure, easier to manage, better performing  - to use two distinct databases.)

While technically you can use the same db user and password for each database, I would never do this in production. I would make them distinct, each database having its own sql user each with privileges to just its own database. 

So:

production config.php

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'productiondb';
$CFG->dbuser    = 'productiondbuser';
$CFG->dbpass    = 'somepassword';
$CFG->prefix    = 'mdl_';


sandbox config.php

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'sandboxdb';
$CFG->dbuser    = 'sandboxdbuser';
$CFG->dbpass    = 'anotherpassword';
$CFG->prefix    = 'mdl_';

Note it is okay that the table prefix is the same in each database, since they are separate databases.

You will of course need to manually create the Sandbox database, its user, and grant it the proper privileges, before starting the install.

In reply to Randy Thornton

Re: Database conflicts between production and sandbox Mdl?

by Bob Heckmann -

Thanks so much for the assistance Randy. I really appreciate it.

Bob

In reply to Bob Heckmann

Re: Database conflicts between production and sandbox Mdl?

by Randy Thornton -
Picture of Documentation writers

No problem. Better safe than sorry when it comes to dbs smile