yum 安装 mysql

安装步骤

  1. 卸载原版本mysql
  2. wget获取安装的源文件
  3. yum安装源文件
  4. yum安装MySQL Server
  5. 配置文件修改默认编码
  6. 启动MySQL服务
  7. 防火墙开启3306端口
  8. 从启动日志获取root密码进入MySQL命令行
  9. 修改root密码
  10. 设置root所有主机可访问
  11. 刷新权限

Shell自动化脚本

mysql-install.sh脚本内容

#!/usr/bin/env bash
yum -y remove `yum list installed | grep mysql | awk "{print $1}"`
[[ ! -e "/docker-init/mysql57-community-release-el7-10.noarch.rpm" ]] && wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
if [[ -z `cat /etc/my.cnf | grep client` ]]; then
    cat /etc/my.cnf >/docker-init/my.cnf
    tee /etc/my.cnf <<-EOF
[client]
default-character-set=utf8
EOF
    cat /docker-init/my.cnf >>/etc/my.cnf
    tee -a /etc/my.cnf <<-EOF
character-set-server=utf8
collation-server=utf8_general_ci
EOF
fi
systemctl start  mysqld.service
systemctl enable mysqld.service
systemctl status mysqld.service
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
password=`grep "A temporary password" /var/log/mysqld.log | awk '{print $11}'`
mysql -uroot -p${password} <mysql-install.sql

mysql-install.sql文件内容

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Swyan234.';
grant all privileges on *.* to 'root'@'%' identified by 'Swyan234.' with grant option;
flush privileges;
use mysql;
select user.User,user.Host from user;

你可能感兴趣的:(Shell,Linux,MySQL)