if [ "${array[0]}" == "Yes" ] && [ "${array[1]}" == "Yes" ] then echo"slave is OK" else error=$(echo"${array[2]}" | sed 's/---/ /g') echo -e "$datetime$slave_ip Slave is not running! \nSlave_SQL_Running_State: $error" >> $mysql_slave_logfile echo -e "时间:$datetime IP:$slave_ip Slave is not running! \n\nSlave_SQL_Running_State: $error" | mail -s "$datetime$slave_ip Slave is not running!(紧急)"$mail
#dumpdbname="liu_emlog printonline_stat" dumpdbname=`/bin/echo show databases | $mysqlbin/mysql -u$mysqlUser -p$mysqlPassword 2>/dev/null | /bin/egrep -wv "Database|information_schema|test"` weekdaynow=`date +%m%d` chmod -R 755 $dumpdir cd $mysqldata echo `date "+%F %T"` backup start >> $dumpdir/backup.log for getdumpdbname in $dumpdbname do
if [ ! -e $dumpdir/$getdumpdbname.$weekdaynow ] then mkdir $dumpdir/$getdumpdbname.$weekdaynow chown mysql.mysql $dumpdir/$getdumpdbname.$weekdaynow fi
for getdumptablename in $dumptablename do $mysqlbin/mysqldump --skip-lock-tables --default-character-set=utf8 $getdumpdbname $getdumptablename > $dumpdir/$getdumpdbname.$weekdaynow/$getdumptablename.dump.`date +%w` done
/usr/local/mysql/bin/mysql -uroot -pmttang mysql>GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'q123456'; //一般不用root帐号,"%"表示所有客户端都可能连,只要帐号,密码正确,此处可用具体客户端IP代替,如192.168.145.226,加强安全。
登录主服务器的mysql,查询master的状态
1 2 3 4 5 6 7
mysql>show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000004 | 308 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化
配置从服务器Slave
1
mysql>change master to master_host='192.168.145.222',master_user='mysync',master_password='q123456',master_log_file='mysql-bin.000004',master_log_pos=308; //注意不要断开,308数字前后无单引号。
+--------------------+ | Database | +--------------------+ | information_schema | | hi_db | //I'M here,大家看到了吧 | mysql | | test | +--------------------+ 4 rows in set (0.00 sec)
mysql> use hi_db Database changed mysql> select * from hi_tb; //查看主服务器上新增的具体数据 +------+------+ | id | name | +------+------+ | 1 | bobu | +------+------+ 1 row in set (0.00 sec)