码迷,mamicode.com
首页 > 数据库 > 详细

Mysql安装脚本

时间:2020-05-26 18:20:45      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:eof   users   pass   tar   mkdir   policy   follow   pack   emctl   

#!/bin/bash

MQL_PACKAGE=/home/kingstar/program/software/rpm包名
MYSQL_Unpack=/home/kingstar/program/software/mysql_tar
MYSQL_ROOT_PASSWORD=Aa123
#2.follow document
if [ `rpm -qa|grep mysql|wc -l` -ne 0 ];then  
    echo -e "yes,you have installed mysql:"  
    rpm -e --nodeps `rpm -qa | grep mysql`  
    fi  


#rpm -qa | grep -i mariadb
if [ `rpm -qa|grep -i mariadb|wc -l` -ne 0 ];then
    echo -e "yes,you have installed mariadb we are uninstalling:"
    rpm -e --nodeps `rpm -qa | grep mariadb`   
    fi 

#1. check if download the mysql rpm package,if not,download

#    mql_rpm_package=`find / -name "mysql*rpm-bundle.tar"`
  
#    mysql_rpm_package_name=mysql*rpm-bundle.tar

#    mysql_d=`find / -name "07mysql" -type d`

#    if [ `find /*/package/02base/07mysql -name "mysql*rpm-bundle.tar"|wc -l` -ne 0 ];then  
#    echo -e "yes,you have the mysql bundle package,it‘s in :$mql_rpm_package"  
    tar xvf $MQL_PACKAGE -C $MYSQL_Unpack
#    else    
#    echo -e "you don‘t have the mysql rpm pakage,but 有离线bundle包就够了\n------------------------"  
   # wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm  
   #echo -e "complete download mysql rpm\n"  
 #   fi

#Inspection group
if [ `cat /etc/group|grep mysql| wc -l` -eq 1 ];then
    echo -e "Group created:"  
    else
    groupadd mysql
    fi 

#Check mysql users
if [ `cat /etc/passwd|grep mysql|wc -l` -eq 1 ];then
    echo -e "User created:"  
    else
    useradd -r -g mysql mysql
    fi

#Go to folder
    cd $MYSQL_Unpack
    echo -e "I came in"

#Install the RPM
#sudo rpm -ivh libaio-*.rpm
sudo rpm -ivh mysql-community-common-5*.rpm
sudo rpm -ivh  mysql-community-libs-5*.rpm
sudo rpm -ivh mysql-community-client-5*.rpm
sudo rpm -ivh mysql-community-server-5*.rpm
echo "The installation is complete"

sudo chown mysql:mysql /var/lib/mysql -R
sudo chmod 777 /var/log
sudo chown mysql:mysql /var/log/mysqld.log -R
mkdir -p /opt/data
mysqld –initialize --user=mysql --datadir=/opt/data

#No password
#sed -i "s/datadir=\/var\/lib\/mysql/datadir=$mql_rpm_package/g" /etc/my.cnf
#sed -i "s/# /skip-name-resolve/g" /etc/my.cnf
sed -i "s/# log_bin/skip-grant-tables/g" /etc/my.cnf
service mysqld restart
sudo chmod 777 /var
mysql -uroot <<EOF
update mysql.user set authentication_string=password(‘$MYSQL_ROOT_PASSWORD‘) where user=‘root‘;
flush privileges;
EOF

#Turn off the firewall
systemctl stop firewalld.service
#Remove passwords and allow remote connections
sed -i "s/skip-grant-tables/skip-name-resolve/g" /etc/my.cnf
echo "Jump out and execute"

service mysqld restart
echo "Mysql is rebooting"

#Ignore the warning
mysql -hlocalhost -P3306 -uroot -pkingstar --connect-expired-password  -A -N <<EOF
set global validate_password_policy=0;
set global validate_password_length=1;
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘$MYSQL_ROOT_PASSWORD‘;
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘$MYSQL_ROOT_PASSWORD‘ WITH GRANT OPTION;
flush privileges;
EOF
service mysqld restart
echo "Configuration is successful"
rm *.rpm
echo "The RPM package was deleted successfully"

echo "Start brushing basic data"
cat $MYSQL_Unpack/*.sql | mysql -uroot -p$MYSQL_ROOT_PASSWORD
echo "Basic data update completed"

 

Mysql安装脚本

标签:eof   users   pass   tar   mkdir   policy   follow   pack   emctl   

原文地址:https://www.cnblogs.com/personsiglewine/p/12966902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!