mysql 安装脚本以及修改密码设置远程连接

1.mysql.sh

#!/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 去除刚才的跳过配置








  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值