#!/bin/bash
#2018-10-13
#旅行者-Travel
#1.安装wget
yum -y install wget
#2、下载mysql的yum源
URL="https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm"
wget $URL -P /etc/yum.repos.d/
yum -y install yum-utils #如果没有该包,下边执行yum-config-manager不生效
yum -y install /etc/yum.repos.d/mysql80-community-release-el7-1.noarch.rpm
if [ $? -eq 0 ];then
rm -rf /etc/yum.repos.d/mysql80-community-release-el7-1.noarch*
fi
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
yum -y install mysql-community-server
sleep 5
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
if [ $? -eq 0 ];then
echo -e "install succefull"
result="`grep 'temporary password' /var/log/mysqld.log`"
p1="`echo $result |awk '{print $NF}'`"
echo "数据库密码为:$p1"
fi
2.脚本执行需要
yum install dos2unix
dos2unix mysql.sh
3.修改密码+设置远程连接
vim /etc/my.cnf
skip-grant-tables
service mysqld restart
mysql -uroot -p
update mysql.user set authentication_string=password('yang521') where user='root' and Host = 'localhost';
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yang521';
flush privileges;
exit;
use mysql;
update user set Host='%' where User='root';
service mysqld restart
vim /etc/my.cnf 去除刚才的跳过配置