In this recipe we will have a look at how to do replication and read-write splitting. We will see how slave and master servers help us in getting these done.
Create a new application using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
Set up the database connection and create a table named
post
, as follows:DROP TABLE IF EXISTS 'blog_post'; CREATE TABLE IF NOT EXISTS 'blog_post' ( 'id' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 'title' VARCHAR(255) NOT NULL, 'text' TEXT NOT NULL, 'created_at' INTEGER, 'modified_at'INTEGER, PRIMARY KEY ('id') );
Generate the
BlogPost
model for the tableblog_post
.Configure master-slave replication between your database servers, for example, as in the article at https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql/.
Configure the
db
component inconfig/main...