Scenario:
Install MySQL Community Server 5.5 x86 64bit RPMs on Red Hat 5 server.#!/bin/sh
TIME_STAMP=`date +%Y-%m-%d_%H_%M_%S`
TMPP_DIR=/tmp
MYSQL_USER=my_user
MYSQL_PASSWORD=my_password
FQDN_HOSTNAME=`hostname -f`
# make sure MySQL Community 5.5 x86 64bit RPMs existence
if [ -e "${TEMP_DIR}/MySQL-shared-5.5.25-1.rhel5.x86_64.rpm" ]; then/bin/chmod a+x ${TEMP_DIR}/MySQL-shared-5.5.25-1.rhel5.x86_64.rpm
else
/bin/echo "${TEMP_DIR}/MySQL-shared-5.5.25-1.rhel5.x86_64.rpm doesn't exist" > "${MY_OUTPUT}"
exit 1
fi
if [ -e "${TEMP_DIR}/MySQL-client-5.5.25-1.rhel5.x86_64.rpm" ]; then
/bin/chmod a+x ${TEMP_DIR}/MySQL-client-5.5.25-1.rhel5.x86_64.rpm
else
/bin/echo "${TEMP_DIR}/MySQL-client-5.5.25-1.rhel5.x86_64.rpm doesn't exist" > "${MY_OUTPUT}"
exit 1
fi
if [ -e "${TEMP_DIR}/MySQL-server-5.5.25-1.rhel5.x86_64.rpm" ]; then
/bin/chmod a+x ${TEMP_DIR}/MySQL-server-5.5.25-1.rhel5.x86_64.rpm
else
/bin/echo "${TEMP_DIR}/MySQL-server-5.5.25-1.rhel5.x86_64.rpm" > "${MY_OUTPUT}"
exit 1
fi
if [ -e "/var/lib/mysql" ]; then
/bin/mv /var/lib/mysql /var/lib/mysql_${MY_TIME_STAMP_STRING}
fi
MY_OUTPUT="/tmp/mysql_rpm_install_output"
MY_MYSQL_RPMS="MySQL-shared MySQL-server MySQL-client"
MYSQL=/usr/bin/mysql
for i in `echo ${MY_MYSQL_RPMS}`
do
/bin/rpm -Uvh --replacepkgs "${TEMP_DIR}/${i}*.rpm" > "${MY_OUTPUT}" 2>&1
if [ "$?" != "0" ]; then
/bin/cat "${MY_OUTPUT}"
exit 1
fi
done
# create MySQL user
$MYSQL -u root -e "CREATE USER '${MYSQL_USER}'@'${FQDN_HOST_NAME}' IDENTIFIED BY '${ FQDN_HOSTNAME }';" > "${MY_OUTPUT}" 2>&1if [ "$?" != "0" ]; then
/bin/cat "${MY_OUTPUT}"
exit 1
fi
# grant MySQL user
$MYSQL -u root -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'${FQDN_HOSTNAME}' IDENTIFIED BY '${MYSQL_PASSWORD}';" > "${MY_OUTPUT}" 2>&1if [ "$?" != "0" ]; then
/bin/cat "${MY_OUTPUT}"
exit 1
fi
# flush privileges
$MYSQL -u root -e "FLUSH PRIVILEGES;"if [ "$?" != "0" ]; then
/bin/cat "${MY_OUTPUT}"
exit 1
fi
# install completed
echo "INSTALLED SUCCESSFULLY"if [ -e "${MY_OUTPUT}" ]; then
/bin/rm -f "${MY_OUTPUT}"
fi
exit 0