Magento 2 个单独的 read/write 数据库连接
Magento 2 separate read/write database connections
在 app/etc/env.php 中为 Magento 2 定义单独的读写连接以分隔 MySQL 数据库的正确方法是什么?
所以这里的关键是将 Magento 1.X 读写连接视为 2.X 中的 master/slave 连接。我相信这是一个仅限企业的功能,因此社区版用户可能不走运。以下是我的 app/etc/env.php 的摘录。我们正在使用 haproxy 来平衡 read/write 到 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' => '',
),
...
在 app/etc/env.php 中为 Magento 2 定义单独的读写连接以分隔 MySQL 数据库的正确方法是什么?
所以这里的关键是将 Magento 1.X 读写连接视为 2.X 中的 master/slave 连接。我相信这是一个仅限企业的功能,因此社区版用户可能不走运。以下是我的 app/etc/env.php 的摘录。我们正在使用 haproxy 来平衡 read/write 到 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' => '',
),
...