I am working with a pre-existing bash file to set up a series of databases for a open source data server (Zotero) and I am running into a mysql structure I am not familiar with:
MASTER="mysql -h localhost -P 3307 -u root -pSomePassword"
SHARD="mysql -h localhost -P 3308 -u root -pSomePassword"
ID1="mysql -h localhost -P 3309 -u root -pSomePassword"
ID2="mysql -h localhost -P 3310 -u root -pSomePassword"
WWW="mysql -h localhost -P 3311 -u root -pSomePassword"
CACHE="mysql -h localhost -P 3312 -u root -pSomePassword"
echo "CREATE DATABASE zoterotest_master" | $MASTER
echo "CREATE DATABASE zoterotest_master" | $SHARD
echo "CREATE DATABASE zoterotest1" | $SHARD
echo "CREATE DATABASE zoterotest2" | $SHARD
echo "CREATE DATABASE zoterotest_ids" | $ID1
echo "CREATE DATABASE zoterotest_ids" | $ID2
It appears there are multiple instances of MySql for some sort of Shard/cluster design but when I look at the db configuration in the php code I see it's connecting to the same port... Now I am confused.
function DBConnectAuth($db) {
if ($db == 'master') {
$host = 'localhost';
$port = 3306;
$db = 'master';
$user = 'root';
$pass = 'SomePassword';
}
else if ($db == 'shard') {
$host = false;
$port = false;
$db = false;
$user = 'root';
$pass = 'SomePassword';
}
else if ($db == 'id1') {
$host = 'localhost';
$port = 3306;
$db = 'ids';
$user = 'root';
$pass = 'SomePassword';
}
else if ($db == 'id2') {
$host = 'localhost';
$port = 3306;
$db = 'ids';
$user = 'root';
$pass = 'SomePassword';
}
else if ($db == 'www1') {
$host = 'localhost';
$port = 3306;
$db = 'www';
$user = 'root';
$pass = 'SomePassword';
}
else if ($db == 'www2') {
$host = 'localhost';
$port = 3306;
$db = 'www';
$user = 'root';
$pass = 'SomePassword';
}
else if ($db == 'cache') {
$host = 'localhost';
$port = 3306;
$db = 'cache';
$user = 'root';
$pass = 'SomePassword';
}
else {
throw new Exception("Invalid db '$db'");
}
return array('host'=>$host, 'port'=>$port, 'db'=>$db, 'user'=>$user, 'pass'=>$pass);
}
My question is, does this look like a typical Shard design? And how do I set it up in MySql - do I just spin up multiple instances on the the ports specified in the Bash or do I have to do something special?
I am tempted to just point everything in the Bash file to 3306 and update the DB shard tables to point to 3306 as well but I have a feeling it isn't that easy.