Preparations: configure the master and slave machines. 1. Modify the mysql configuration file my. cnf, the file in the etc directory in the [mysqld] configuration section to add the following field server-id1log-binlogbinlog-do-dbrepl to the database to be synchronized, if there is no line, it means to synchronize all databases this parameter can be repeated
Preparations: configure the master and slave machines. 1. Modify the mysql configuration file my. cnf, in the/etc directory, add the following field server-id = 1 log-bin = log binlog-do-db = repl in the [mysqld] configuration section. // the database to be synchronized, if the row does not exist, it means synchronizing all databases. This parameter can be repeated.
Preparations:
Configurations of master and slave machines
1. Modify the mysql configuration file my. cnf on the master machine, which is in the/etc directory.
Add the following fields in the [mysqld] configuration section:
Server-id = 1
Log-bin = log
Binlog-do-db = repl // the database to be synchronized. If no row exists, this parameter can be set repeatedly to synchronize all databases. This parameter may cause problems and is not required as much as possible, filter data settings to slave Database
Binlog-ignore-db = mysql // The same as the ignored database. It is best not to filter the settings to the slave database.
Modify the mysql configuration file on the server Load balancer instance
Add the following content in the [mysqld] Field
Server-id = 2
Master-host = 192.168.1.222
Master-user = repl
Masters-password = 123456
Master-port = 3306
Master-connect-retry = 60
# Replicate-ignore-db = the same as databases ignored by mysql.
# Master-connect-retry = 60 if the master server is disconnected from the server, the time difference between the reconnection (seconds)
# Replicate-do-db = repl // synchronous database (name of the database to be backed up). If this row is left blank, all databases are synchronized.
# The following two parameters are recommended:
Replicate-wild-do-table = db_name. %
Replicate-wild-ignore-table = mysql. %
Restart the mysql instance of the Server Load balancer instance.
Bytes -------------------------------------------------------------------------------------------------
1. log on to mysql and first check the database version.
> Select version ();
2. Check the server_id of the master database and slave Database
> Show global variables like 'server _ id ';
3. Check whether the binary file of the master database is enabled.
> Show global variables like 'Log _ bin ';
If not, restart the database:
(1) In the my. cnf parameter file, add
Log-bin = mysql-bin
(2) restart the MySQL database.
4. Check whether the slave database's network and port are reachable.
# Netstat-tnlp | grep mysqld
# Telnet 192.168.230.71 3306.
5. Create a synchronization account in the master database and authorize replication
> Create user 'repl' @ 'host' identified by 'Password ';
> Grant replication slave, replication client on *. * to 'repl' @ 'host ';
6. Test whether repl user logon can be performed from the database.
# Mysql-urepl-ppassword-hhost-P3306
7. Record the current binary log name and offset on the master database master
It is mainly used to specify the start position in slave.
> Show master status \ G
8. Back up the database
Enable master-slave Replication
Slave start;
View Master/Slave Information
Show slave status \ G;
If slave_IO_Running: yes and Slave_ SQL _Runnning: yes are printed, the configuration is successful.