First install the mysql database on the two servers:
Linux common users install MySQL database, mysql-5.7.24 version, ContOS8 version server
The server-id in the my.cnf file of the two installed databases must be unique, and the my.cnf configuration file needs to be modified if it is repeated:
Server 1: 10.0.84.25
Server 2: 10.0.84.26
After the installation is complete, restart the two mysql databases:
service mysql restart
Log in to the mysql database:
mysql -uroot -p
View the status of the MySQL master database on server 10.0.84.26:
show master status;
Change the corresponding data:
#MASTER_LOG_FILE='binlog.000002', (it is the File in the status information)
#MASTER_LOG_POS=154; (it is the Position in the status information)
CHANGE MASTER TO
MASTER_HOST='10.0.84.26',
MASTER_PORT=3306,
MASTER_USER='mysql',
MASTER_PASSWORD='mysql123',
MASTER_LOG_FILE='binlog.000002',
MASTER_LOG_POS=154;
Log in to the MySQL database on the server 10.0.84.25 to execute:
start the I/O thread and the SQL thread:
start slave;
View the status of the MySQL master library on server 10.0.84.25:
show master status;
Change the corresponding data:
#MASTER_LOG_FILE='binlog.000005', (it is the File in the status information)
#MASTER_LOG_POS=154; (it is the Position in the status information)
CHANGE MASTER TO
MASTER_HOST='10.0.84.25',
MASTER_PORT=3306,
MASTER_USER='mysql',
MASTER_PASSWORD='mysql123',
MASTER_LOG_FILE='binlog.000005',
MASTER_LOG_POS=154;
Log in to the MySQL database on server 10.0.84.26 to execute:
start the I/O thread and SQL thread:
start slave;
Use the command to view the status of the two machines separately:
show slave status\G;
Both machines have the following two states, which means they are normal:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Exit, and log in to each other's database to see if they are connected:
mysql -umysql -p -h10.0.84.26
mysql -umysql -p -h10.0.84.25
Finally, connect with a visualization tool to create a database table, and test to see if the two databases are synchronized.