需要帮助写通过单个Magento安装多个数据库 [英] Need help writing to multiple database through single Magento installation
问题描述
我刚刚接触Magento(我喜欢它),开发一个桌面应用程序,与我们的Magento CE 1.7商店并排运行。桌面应用程序将拥有自己的数据库,但我们需要从magento获取几乎所有的信息。
所以,我已经复制了magento的整个数据库,并在应用程序的数据库。我需要的是写入应用程序的数据库,当有一些东西写在magento的数据库通过magento的网站。我们不需要从应用程序的数据库中读取,只写。
我需要做什么和需要做哪些改变?我真的很感激,如果有人可以提供我一些深入的指导。请帮助我。
谢谢。
处理只读从属
Magento 本身能够分离读/写到不同的数据库服务器(除了几个断开的版本,例如EE 1.11) - 允许您偏移选择
加载到其他(或更多)服务器;并将所有更新/写入
查询转发给单个主机。
配置从属
首先配置您的从站。我们是Percona实用程序和MySQL分支机构的大力倡导者 - 他们有一个理想的工具来对现有的DB - innobackupex进行热备份。 这里有一个好的写法。
替换$ TIMESTAMP或制表符完成
mysql
> GRANT REPLICATION SLAVE ON *。* TO'repl'@'$ slaveip'IDENTIFIED BY'$ slavepass';
>放弃;
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;
>开始从属;
然后,一旦你的slave被操作,在实践中,它只需要几行代码来实现。
在 ./ app / etc / local.xml
$ b b
< 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>
来源
I'm new to Magento (I am loving it) and developing a desktop application to run side-by-side with our Magento CE 1.7 store. The desktop application will have it’s own database but we need to fetch almost all information from magento.
So, I have already copied the whole database of magento and used it in the application’s database. What I need is to write in the application’s database too when there is something written in the magento’s database through magento’s site. We do not need to read from application’s database, only write.
What changes will I need to do and where? I would really appreciate if someone can provide me some in-depth guide. Please help me.
Thank you.
Can Magento natively handle read-only slaves
Magento is natively capable of splitting off reads/writes to different database servers (with the exception of a few broken releases, eg. EE 1.11) - allowing you to offset select
load to an additional (or more) server(s); and forwarding all the update/write
queries to a single master.
Configuring the slaves
First configure your slaves. We're big advocates of the Percona utilities and MySQL branches - they have an ideal tool for taking hot backups of your existing DB - innobackupex. There is a good write up here.
On the master
Replace $TIMESTAMP or tab complete.
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
On the slave
/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;
Then once your slave is operational, in practice, it only takes a few additional lines of code to achieve.
In ./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>
Sources
这篇关于需要帮助写通过单个Magento安装多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!