–安装MySQL-server、MySQl-client软件包
–修改数据库用户root的密码
–确认MySQL服务程序运行、root可控
描述:(1)使用64位的RHEL 7操作系统,MySQL数据库的版本是5.7.17
(2)访问http://dev.mysql.com/downloads/mysql/,找到MySQL Community Server下载页面,平台选择“Red Hat Enterprise Linux 7/ Oracle Linux”,然后选择64位的bundle整合包下载,即可。
#!/bin/bash
#AUTHOR:ZHD
#DATE:2019-05-19
#FUNCTION:快速搭建MySQL服务
#VERSION:1.0
#定义mysql启动函数
function mysql_start {
systemctl restart mysqld
}
#定义输出颜色函数
function cecho {
echo -e "\033[$1m$2\033[0m"
}
#用户设置服务密码
function secert {
while :
do
stty -echo
read -p "Please input password:" p1
echo " "
stty echo
stty -echo
read -p "Please input password again:" p2
echo " "
stty echo
if [ $p1 = $p2 ];then
cecho 32 "Set password Successfully!!"
exit
else
cecho 31 "The password set twice is different,Please re-enter!!"
fi
done
}
#主程序安装MySQL
function install_mysql {
cd /root/soft/mysql
cecho 32 "The system is packing,Just a moment,please....."
yum -y install mysql-community-*.rpm
cecho 32 "MySQL service is starting,Just a moment,please....."
mysql_start
cecho 32 "MySQL service to start successfully!!"
password=$(grep 'temporary password' /var/log/mysqld.log | tail -1 | awk '{print $11}')
mysql --connect-expired-password -hlocalhost -uroot -p$password -e "alter user root@'localhost' identified by '123qqq...A';" &> /dev/null
sed -i "4a validate_password_length=6" /etc/my.cnf
sed -i "4a validate_password_policy=0" /etc/my.cnf
mysql_start
mysql --connect-expired-password -uroot -p123qqq...A -e 'update mysql.user set authentication_string=password("123456") where user="root" and host="localhost";' &> /dev/null
mysql_start
cecho 32 +++++++++++mysql服务成功搭建!+++++++++
}
install_mysql