Method MYSQL master configuration database synchronization from the backup

Following step by step to introduce a very detailed, specific information, please see below it.

First, prepare

Do the test with two servers:

Master Server: 192.0.0.1/Linux/MYSQL 4.1.12
Slave Server: 192.0.0.2/Linux/MYSQL 4.1.18  

    Call the shots from the principle that server, MYSQL version to be the same, if not met, at least from MYSQL server version must be higher than the master server version of MYSQL

Second, configure the master server

1. Log Master server, edit my.cnf

#vim /etc/my.cnf

Add the following in the [mysqld] section:

?

1234 log-bin=mysql-binserver-id=1binlog-do-db=extmailbinlog-ignore-db=mysql,test

Explain: log-bin entry is to let the Master server binary log recording is required;
Server-ID = master_id wherein master_id must be a positive integer value between 1 and 232-1;
the binlog-do-DB = Database is to be recorded log database;
the binlog-DB is not the ignore-log records database name, a plurality of intermediate database separated by commas (,);

2. Add the slave server from a master server from a master server has permission to access the account, see the following command to know:

mysql> grant replication slave on *.* 
-> to 'abc'@'192.0.0.2' identified by '123';

Format: MySQL> GRANT REPLICATION SLAVE ON * *
   -> the TO 'account' @ 'from the server IP or hostname' IDENTIFIED BY 'password';

3. restart Mysql

4. The master database backup data

# mysqldump --master-data extmail > extmail_backup_20071120.sql

Option to add --master-data, where the data backup of the master server, the server back to import slave.

5. View Master state

?

  mysql> show master status;+------------------+----------+--------------+------------------+| File       | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000002 |    79 | extmail   | mysql,test    |+------------------+----------+--------------+------------------+1 row in set (0.00 sec)

Third, the slave server configuration

1. Edit my.cnf

# vim /etc/my.cnf

Add the following in the [mysqld] section:

server-id=2
master-host=192.0.0.1
master-port=3306
master-user=abc
master-password=123
master-connect-retry=60

Explanation: 

a slave server's master server-id can not be the same, among a plurality of server-id can not be the same slave.
master-host is the host name or IP address of the master server's
master-user and master-password is in front of us to build a user name and password on the master
master-Connect-retry from the server if the primary server is found broken, reconnect time difference

2. backup from the primary database into the database server from the server, which is in front of us extmail_backup_20071120.sql

# mysqladmin create extmail
# mysql extmail < extmail_backup_20071120.sql

3. restart mysql server

4. Stop slave service, various parameters of the primary server

?

  mysql> slave stop;mysql> change master to-> MASTER_HOST='192.0.0.1',-> MASTER_USER='abc',-> MASTER_PASSWORD='123',-> MASTER_LOG_FILE='mysql-bin.000002',-> MASTER_LOG_POS=79;mysql> slave start;

5. Check the state of the primary server

mysql> show processlist;


Author: ajax Jumpstart foundation
link: https: //www.imooc.com/article/44346
Source: Mu class network

Guess you like

Origin www.cnblogs.com/HKROnline-SyncNavigator/p/10971757.html