linux-tutorial/codes/linux/soft/mysql-install.sh

65 lines
1.9 KiB
Bash
Raw Normal View History

2019-07-11 16:52:03 +08:00
#!/usr/bin/env bash
2019-07-29 10:46:59 +08:00
###################################################################################
# 控制台颜色
BLACK="\033[1;30m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
PURPLE="\033[1;35m"
CYAN="\033[1;36m"
RESET="$(tput sgr0)"
###################################################################################
printf "${BLUE}"
cat << EOF
###################################################################################
# 安装 mysql 脚本
# @system: 适用于 Centos7 发行版本。
# @author: Zhang Peng
###################################################################################
EOF
printf "${RESET}"
printf "${GREEN}>>>>>>>> install mysql begin.${RESET}\n"
2019-07-11 16:52:03 +08:00
2019-10-29 18:22:19 +08:00
command -v wget > /dev/null 2>&1 || {
printf "${RED}Require wget but it's not installed.${RESET}\n";
exit 1;
}
command -v rpm > /dev/null 2>&1 || {
printf "${RED}Require rpm but it's not installed.${RESET}\n";
exit 1;
}
command -v yum > /dev/null 2>&1 || {
printf "${RED}Require yum but it's not installed.${RESET}\n";
exit 1;
}
2019-07-29 10:46:59 +08:00
# 使用 rpm 安装 mysql
2019-11-26 17:11:53 +08:00
printf "${CYAN}>>>> yum install mysql${RESET}\n"
2019-07-29 10:46:59 +08:00
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2019-07-11 16:52:03 +08:00
sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
sudo yum install mysql-community-server
2019-07-29 10:46:59 +08:00
2019-11-26 17:11:53 +08:00
printf "${CYAN}>>>> replace settings${RESET}\n"
cp /etc/my.cnf /etc/my.cnf.bak
wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/mysql/my.cnf -O /etc/my.cnf
# 创建空的慢查询日志文件
touch /var/log/mysqld-slow.log
chmod 777 /var/log/mysqld-slow.log
2019-07-29 10:46:59 +08:00
# 设置开机启动
2019-11-26 17:11:53 +08:00
printf "${CYAN}>>>> start mysqld${RESET}\n"
2019-07-29 10:46:59 +08:00
systemctl enable mysqld
2019-11-26 17:11:53 +08:00
systemctl start mysqld
2019-07-29 10:46:59 +08:00
systemctl daemon-reload
password=$(grep "password" /var/log/mysqld.log | awk '{print $NF}')
printf "临时密码为:${PURPLE}${password}${RESET},请登录 mysql 后重置新密码\n"
printf "${GREEN}<<<<<<<< install mysql end.${RESET}\n"