Mysql安装脚本

Posted personsiglewine

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql安装脚本相关的知识,希望对你有一定的参考价值。

#!/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包就够了
------------------------"  
   # wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm  
   #echo -e "complete download mysql rpm
"  
 #   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安装脚本的主要内容,如果未能解决你的问题,请参考以下文章

Rehat一键安装mysql脚本和备份数据库脚本

Unity中timeline出现脚本错误怎么解决

部分代码片段

shell脚本一键安装mysql5.7.x

html 将以编程方式附加外部脚本文件的javascript代码片段,并按顺序排列。用于响应式网站,其中ma

;~ 小部分AutoHotkey源代码片段测试模板2019年10月9日.ahk