Master Slave Configuration in Laravel 5.5
Asked Answered
S

1

6

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

Sealer answered 9/12, 2017 at 4:55 Comment(1)
laracasts.com/discuss/channels/laravel/…Regardant
C
14

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'    => '',
],
Cube answered 9/12, 2017 at 14:11 Comment(4)
What happened if there isn't internet connection and master would be on live, Will it run automatically when gets an internet connection?Languorous
separating read and write mode is not the concept of master-slaveBurdock
@Burdock then what is the concept of master-slave?Cube
Pretty sure that separating read and write mode is a major part of the concept of master-slave. You want to read the local data, but write to the master server. If you read and write to the master server only, then why are you replicating the data in the first place?Free

© 2022 - 2024 — McMap. All rights reserved.