Configure Mysql-slave database
Step 1: Create a database
Now come to the other server where we are configuring slave server. If mysql server is not installed, then run the commands which are provided at the start of this article.
Once the installation is done login to the slave server and create the new database that you will be replicating from the master.
$ mysql -u root -p
$ CREATE DATABASE testdb;
Step 2: Import the database
Now you need to import the database that you previously exported from master Database.
$ mysql -u root -p testdb < testdb.sql
Step 3: Configuration of slave in my.cnf
Now we need to configure the slave server the same way we did for master server.
#Change the server-id and use different no. here we have used no. 2 as server-id.
server-id = 2
#Following that, make sure that you have the following three criteria appropriately filled out.
relay-log = /var/log/mysql/mysql-relay-bin.log
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = testdb
#Note: You need to create a relay-log file in mentioned path because it is not there by default.
After all the necessary changes save and close the file.
Restart Mysql Server:
$ sudo /etc/init.d/mysql restart
Step 4: Enable the replication
Now we need to enable the replication using the mysql shell. Open up the mysql shell and run the below mentioned commands.
$ mysql -u root -p
# Replace the values to match your information.
$ CHANGE MASTER TO MASTER_HOST='192.168.3.213',MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=557;
#Activate the Slave server.
$ START SLAVE;
# You be able to see the details of the slave replication by typing in this command. The G rearranges the text to make it more readable.
$ SHOW SLAVE STATUSG
That is it. Master-Slave replication configuration is completing here. Now you can test by updating any single value in the master database and check this same on slave database. You can see the changes are updating on slave database.
I hope you like the article if you find any difficulties then please do comment your queries or problem via the comment section, till then stay tuned to techthings.org for more such valuable articles.