#!/bin/bash #install mysql for binary wget_mysql_package () { flag=$(rpm -q wget &>/dev/null ; echo $?) if [ $flag -ne 0 ];then yum install wget -y fi if [ ! -d /opt/software ];then mkdir -p /opt/software/application fi mysql_url=https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar mysql_package=$(echo $mysql_url|awk -F/ '{print $7}') mysql_directory=$(echo $mysql_url|awk -F/ '{print $7}'|cut -d. -f1-4) wget -P /opt/software/ $mysql_url if [ ! -f /opt/software/$mysql_package ];then echo "mysql package is not download" exit fi cd /opt/software/ tar -xvf /opt/software/$mysql_package if [ $? -ne 0 ];then echo "mysql package tar faild" exit fi if [ ! -f /opt/software/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz ];then echo " file is not exsit" exit fi tar -xvzf /opt/software/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz ln -s /opt/software/mysql-5.7.29-linux-glibc2.12-x86_64 /opt/software/mysql } install_mysql () { ############定义变量################## export PATH=/opt/software/mysql/bin:$PATH ############创建mysql用户############# useradd -s /bin/nologin -M mysql id mysql &>/dev/null if [ $? -ne 0 ];then exit fi #########创建mysql的数据目录######### mkdir -p /data/mysql chown -R mysql:mysql /data/mysql chown -R mysql:mysql /opt/software/mysql ########初始化数据库################ mysqld --initialize-insecure --user=mysql --basedir=/opt/software/mysql --datadir=/data/mysql #######mysql config################ cat >/etc/my.cnf <<EOF [mysqld] user=mysql basedir=/opt/software/mysql datadir=/data/mysql socket=/tmp/mysql.sock port=3306 server_id=1 [mysql] socket=/tmp/mysql.sock EOF } mysql_start () { cp -a /opt/software/mysql/support-files/mysql.server /etc/init.d/mysql /etc/init.d/mysql start netstat -tanp |grep 3306 } wget_mysql_package install_mysql mysql_start