douliao5942 2017-07-20 20:49
浏览 91
已采纳

设置MySql Sharding或绕过它

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.

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 求一个超难的动态新增元素的 click 事件无效的解决办法。
      • ¥20 怎么修改mediawiki允许上传的文件大小?
      • ¥15 agrySEXPAYm 是毒吗
      • ¥50 Java实现注册登录实现数据库增删改查功能,数据库至少两个表
      • ¥20 求解R语言的数据分析问题
      • ¥20 求GD32F105和305解除读保护方法教程
      • ¥15 C++代码优化,复杂度太高,无法通过clang-tidy检查,用什么办法可以优=化
      • ¥15 关于跨链隐私保护方案
      • ¥15 node mongodb 根据id给子集合list添加对象 请问应该如何操作
      • ¥50 如何得到路径下的绝对路径并且回传到list上