Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Master Slave Configuration in Laravel 5.5

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. ?

like image 519
Subhajit Avatar asked Dec 09 '17 04:12

Subhajit


People also ask

What is the difference between master and slave table?

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.

Is master slave asynchronous?

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.


1 Answers

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'    => '',
],
like image 107
Paras Avatar answered Oct 03 '22 15:10

Paras