#!/bin/bash
mycnf=" /etc/my.cnf"
sed -i '/symbolic-links=0/a\skip-grant-tables=1' $mycnf
service mysqld restart
if [ `rpm -qa | grep expect | wc -l` -eq 0 ]
then
yum clean all
yum install -y expect
fi
/usr/bin/expect <<-EOF
spawn mysql -uroot
expect "*mysql>"
send "use mysql;\r"
send "update user set authentication_string = password('root'), \
password_expired = 'N', password_last_changed = now() where user = 'root';\r";
send "flush privileges;\r"
send "delete from user where user<>'root';\r"
send "update user set host='%' where user='root';\r"
send "flush privileges;\r"
send "grant all PRIVILEGES on *.* to 'slave'@'%' identified by 'slave';\r"
send "flush privileges;\r"
expect "*mysql>"
send "exit;\r";
expect eof
EOF
sed -i -e '/skip-grant-tables=1/d' $mycnf
service mysqld restart