【问题标题】:Magento 2 separate read/write database connectionsMagento 2 独立的读/写数据库连接
【发布时间】:2017-09-12 10:54:31
【问题描述】:

对于 Magento 2,在 app/etc/env.php 中为单独的 MySQL 数据库定义单独的读写连接的正确方法是什么?

【问题讨论】:

    标签: mysql magento2


    【解决方案1】:

    所以这里的关键是将 Magento 1.X 读写连接视为 2.X 中的主/从连接。我相信这是一项仅限企业的功能,因此社区版用户可能不走运。下面是我的 app/etc/env.php 的摘录。我们正在使用 haproxy 来平衡到 Percona 集群的读/写连接,因此除非您有相同的设置,否则您需要将主机配置为适当的 IP。

    ...
    'db' =>
        array (
            'connection' =>
                array (
                    'default' =>
                        array (
                            // HaProxy Write (master) connection
                            'host' => '127.0.0.1:3308',
                            'port' => '3308',
                            'dbname' => 'magento_db',
                            'username' => 'username',
                            'password' => 'password',
                            'active' => '1',
                        ),
    
                ),
            'slave_connection' =>
                array (
                    'default' =>
                        array (
                            // HaProxy Read (slave) connection
                            'host' => '127.0.0.1:3307',
                            'port' => '3307',
                            'dbname' => 'magento_db',
                            'username' => 'username',
                            'password' => 'password',
                            'active' => '1',
                        ),
                ),
            'table_prefix' => '',
        ),
    ...
    

    【讨论】:

    猜你喜欢
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多