1

I am experiencing the following scenario:

I want to split my database into separate read and write databases. For that reason i've setup the config/database.php

    'mysql' => [
        'driver' => 'mysql',
        'write' => ['host' => env('DB_HOST_WRITE', 'localhost'),],
        'read'  => ['host' => env('DB_HOST_READ', 'localhost'),],
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

For DB_HOST_WRITE and DB_HOST_READ I've set the IP addresses for the servers where the databases are running on.

For DB_DATABASE, DB_USERNAME, DB_PASSWORD I've setup the database name and the login credentials.

Both servers are reachable, when I try to access them using mysql console commands like this: mysql -u USERNAME -h IPADDRESS -p

Here is the problem: When I attempt to run my migrations from a third server like this

php artisan migrate

But only the write database gets set up.

Is this the expected behaviour?

Do I have to migrate each database manually?

Is there a flag for the migration command, that allows me to specify the connection i want to migrate on?

I cant find anything about read write database migrations when I google for it.

There was no further database setup done. My information source is the following guide: https://laravel.com/docs/5.7/database#read-and-write-connections

Links to useful guides or solution suggestions are very welcome.

Thanks for your attention.

Daniel
  • 9,491
  • 12
  • 50
  • 66
Richard Wieditz
  • 406
  • 1
  • 4
  • 14

1 Answers1

0

to @Travis Britz: Thanks for the hint. I was missing the term "MySQL Replication", what is not commented in the laravel documentations. I was mistakenly thinking laravel algorithms are handling the synchronisation on their own, what is in fact not happening.

Synchronization between databaseservers is handled by MySQL internal mechanisms

enter image description here

With these MySQL algorithms I was able to achieve a communication structure like that, what might be a common task in the deployment step of web applications:

enter image description here

I followed this guide by digital ocean to setup a mysql replication manually: https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql

Digital Ocean is the server provider i'm hosting my applications at.

Images are taken from: https://www.toptal.com/mysql/mysql-master-slave-replication-tutorial

Best regards.

Richard Wieditz
  • 406
  • 1
  • 4
  • 14