需要帮助通过单个Magento安装写入多个数据库

时间:2013-02-08 14:48:46

标签: mysql database magento magento-1.7

我是Magento的新手(我喜欢它)并开发了一个与我们的Magento CE 1.7商店并排运行的桌面应用程序。桌面应用程序将拥有自己的数据库,但我们需要从magento中获取几乎所有信息。

所以,我已经复制了整个magento数据库并在应用程序的数据库中使用它。我需要的是在magento的数据库中通过magento的站点写入内容时,也可以在应用程序的数据库中写入。我们不需要从应用程序的数据库中读取,只需要写。

我需要做哪些更改以及在哪里?如果有人能给我一些深入的指导,我真的很感激。请帮帮我。

谢谢。

3 个答案:

答案 0 :(得分:2)

Magento可以原生处理只读从属

Magento 本身能够将读/写分离到不同的数据库服务器(除了一些破坏的版本,例如EE 1.11) - 允许您偏移select加载到一个或多个(或更多)服务器;并将所有update/write个查询转发给单个主人。

配置从属设备

首先配置你的奴隶。我们是Percona实用程序和MySQL分支的主要倡导者 - 他们拥有一个理想的工具,用于对现有数据库进行备份 - innobackupex。 有一个很好的写作here

在主人

替换$ TIMESTAMP或制表符完成。

mysql
> GRANT REPLICATION SLAVE ON *.*  TO 'repl'@'$slaveip' IDENTIFIED BY '$slavepass';
> quit;
innobackupex --user=username --password=password /path/to/backupdir
innobackupex --user=username --password=password /
       --apply-log /path/to/backupdir/$TIMESTAMP/

rsync -avprP -e ssh /path/to/backupdir/$TIMESTAMP TheSlave:/path/to/mysql/
scp /etc/mysql/my.cnf TheSlave:/etc/mysql/my.cnf

在奴隶上

/etc/init.d/mysql stop
mv /path/to/mysql/datadir /path/to/mysql/datadir_bak
mv /path/to/mysql/$TIMESTAMP /path/to/mysql/datadir
chown -R mysql:mysql /path/to/mysql/datadir
sed -i 's#server-id=1#server-id=2#g' /etc/mysql/my.cnf
/etc/init.d/mysql start
cat /var/lib/mysql/xtrabackup_binlog_info
> TheMaster-bin.000001     481

mysql
> CHANGE MASTER TO MASTER_HOST='$masterip', MASTER_USER='repl', MASTER_PASSWORD='$slavepass', MASTER_LOG_FILE='TheMaster-bin.000001', MASTER_LOG_POS=481;
> START SLAVE;

然后,一旦你的奴隶可以运作,实际上,只需要几行额外的代码即可实现。

./app/etc/local.xml

<default_read>
  <connection>
    <use/>
    <host><![CDATA[host]]></host>
    <username><![CDATA[username]]></username>
    <password><![CDATA[password]]></password>
    <dbname><![CDATA[dbname]]></dbname>
    <type>pdo_mysql</type>
    <model>mysql4</model>
    <initStatements>SET NAMES utf8</initStatements>
    <active>1</active>
  </connection>
</default_read>

来源

答案 1 :(得分:1)

要处理多个数据库,您应该执行以下操作:

1°)在/app/etc/local.xml中创建数据库连接:

你有类似的东西:

        <default_setup>
            <connection>
                <host><![CDATA[localhost]]></host>
                <username><![CDATA[user]]></username>
                <password><![CDATA[password]]></password>
                <dbname><![CDATA[dbname]]></dbname>
                <active>1</active>
            </connection>
        </default_setup>

处理你的mysql数据库。在此处添加另一个节点以处理新连接

 <mysetup>
<connection>
<host>192.168.5.10</host> <!-- host of my local server -->

<username>user</username>
<password>passwd</password>
<dbname>d:\pathtomydb\bin\dbname.FDB</dbname>
<active>1</active>
   </connection>
   </mysetup>

现在你有了另一个联系。

我是一只火鸟,所以你可以对此进行一些改动,但这就是我的处理方式:

Connexion:

 $config = Mage::getConfig()->getResourceConnectionConfig('mysetup');

        $dbConfig = array(
        'host'      => $config->host,
        'username'  => $config->username,
        'password'  => $config->password,
        'dbname'    => $config->dbname
    );
        $connexion = Zend_Db::factory('Firebird', $dbConfig);

将Firebird替换为您需要的连接类型(如Pdo_Mysql或类似的东西)。 查询:

 $connexion->fetchAll($request);
 $connexion->update('table',array('field'=>'value'),$where);

答案 2 :(得分:0)

如果您的DNS支持,您可以使用加权路由策略创建记录集。与AWS Route 53一样。为了避免停机,您可以将其与健康检查相关联。

一个例子:https://aws.amazon.com/pt/blogs/aws/domain-name-health-checks-for-route-53/