How to configure Laravel 5.5 with master slave MySQL replication ?
I want to make write operations and read operations in master and slave respectively .
Optional: Is there any way to do connection pooling and max / min no of open connections in ideal conditions. ?
Slave is a device or a process that is controlled by another device or a process (called the master). For example, in database replication, the database considered as the slave will use the updates recorded in the master database to synchronize its data with the master.
The classical master-slave configuration allows synchronizing pairs of unidirectionally coupled systems or oscillators in a relatively easy manner. However, it has been found that this scheme has a limitation: for certain systems—including those with chaotic dynamics—this scheme fails to induce synchronization.
Just change your config/database.php
file to include read (slave) and write (master) hosts like so like the Laravel docs suggest:
'mysql' => [
'read' => [
'host' => '192.168.1.1',
],
'write' => [
'host' => '196.168.1.2'
],
'sticky' => true,
'driver' => 'mysql',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With