Production environment mysql database master-slave recovery slave database

Failure; system hard drive damaged, completely reinstalled

Faulty machine: 172.16.100.32

The main machine from which recovery is based; 172.16.100.31

1. 

After the reinstallation is complete, copy the master main library vs/program directory, and then clear the data directory of the database.

Make sure that there is an empty data directory in the mysql directory, and the owner group of the entire directory is clouder

chown -R clouder.clouder /home/clouder/vs/program/mysql/data/

2. Use the clouder user to initialize the mysql database

scripts/mysql_install_db --user=clouder --basedir=/home/clouder/vs/program/mysql --datadir=/home/clouder/vs/program/mysql/data/pmp

3.

Modify the main configuration file master.cfg, just modify the server-id

server-id = 112

4.

5.mysqldump logical backup database

Log in to the main database and dump all databases

mysqldump -h172.16.254.117 -uroot -P5505 -pengine2ocean -R --all-databases  -R --master-data=2 --flush-logs > /home/clouder/alldatabase`date +%F-%H-%M-%S`.sql

--all-databases : The backed up sql statement includes the database build statement

-R : stored procedures and triggers

6.

1 Restore from library

   start the service

/home/clouder/vs/program/mysql/bin/mysqld --defaults-file=/home/clouder/vs/program/mysql/conf/master.cnf &

1) Login

mysql -uroot -p

2) Temporarily turn off the binary log

mysql> SET  sql_log_bin = 0

3) Restore the database

mysql> source /home/clouder/backup/alldatabase2017-04-17-14-55-08.sql

4) Enable binary log

mysql> SET sql_log_bin =1;

mysql> flush privileges;

 

1) View the binary log file and corresponding location recorded at the beginning of the sql file of mysqldump

-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=107;

2) Establish master-slave replication

change master to master_host='172.16.100.31',master_user='slave',master_password='engine',master_port=5505, master_log_file='mysql-bin.000005',MASTER_LOG_POS=107;

start slave;

'margin-left:21.0pt;text-indent:-21.0pt; mso-char-indent-count:0;mso-list:l0 level1 lfo1'>4) Enable binary log

 

mysql> SET sql_log_bin =1;

mysql> flush privileges;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325680819&siteId=291194637