[BlueOnyx:25974] Re: Adding existing mysql database/users

Michael Stauber mstauber at blueonyx.it
Thu Feb 16 21:01:49 -05 2023


Hi Darren,

> Is there a way of adding an existing mysql database and mysql user to an 
> existing vsite, so that it then appears and can be managed in the gui?

In 5210R/5211R under "Site Management" / <Site> / "Services" / "MariaDB" 
you can simply edit "Allowed Databases" to allow more databases.

This also works on 5209R, but there the option for it is listed under 
"Site Management" / <Site> / "Services" / "Web" and it's also named 
"Allowed Databases".

> I need to do this in bulk too, so a scriptable cli method would be ideal!

This will do the trick and it'll work on 5209R/5210R/5211R:

------------------------------------------------------------------------
#!/usr/bin/perl -I/usr/sausalito/perl

# How many DBs do we allow?
$maxDBs = '10';

use CCE;
my $cce = new CCE;
$cce->connectuds();

# Find all Vsites:
my @vhosts = ();
my (@vhosts) = $cce->findx('Vsite');

print "Going through all sites to set MariaDB 'maxDBs' to: $maxDBs: \n";

# Walk through all Vsites:
for my $vsite (@vhosts) {
     ($ok, my $my_vsite) = $cce->get($vsite);
     print "Processing Site: $my_vsite->{fqdn} \n";
     ($ok) = $cce->set($vsite, 'MYSQL_Vsite', { 'maxDBs' => $maxDBs });
}

# Close CCEd connection and exit:
$cce->bye('SUCCESS');
exit(0);
------------------------------------------------------------------------

Just edit line 4 ...

$maxDBs = '10';

... to reflect the number of DBs you want to grant and execute the 
script. It'll walk through all existing Vsites and it will set this value.

You need to run this script as "root".

Please note: It won't enable MariaDB/MySQL if a Vsite doesn't have it 
enabled yet.

-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list