Automatic installation of MySQL5.6

Source: Internet
Author: User
Tags unpack

MySQL5.6 Script Automatic Installation

---------

#! /bin/bash

Source/etc/profile

# Install MySQL5.6

#MySQL安装包

Mysql= "Mysql-5.6.35-linux-glibc2.5-x86_64"

#MySQL

Mysql_url= "Http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz"

#MySQL安装目录

Mysql_basedir= "/usr/local"

#MySQL数据库目录

Mysql_data= "/data/mysql"

Mysql_datedir= "$Mysql _data/data"

#MySQL用户

User=mysql

mkdir $Mysql _data/{tmp,binlog,log}-P

#网卡路径

eth0= '/etc/sysconfig/network-scripts/ifcfg-eth0 '

em1= '/etc/sysconfig/network-scripts/ifcfg-em1 '

If [-F $Eth 0];then

Ip_add= "$Eth 0"

Else

If [-F $Em 1];then

ip_add= $Em 1

Else

echo "Error The script cannot recognize the configuration file of the network card"

Fi

Fi

Ip= "' grep ipaddr $IP _add | Awk-f ' [=] ' {print $} ' "

#获取网卡的IP的最后一位

Ip2= "' grep ipaddr $IP _add | Awk-f ' [=.] ' ' {print $} ' "


#如果检测到已经安装了MySQL, Prompt for y, uninstall the old version, and then start installing MySQL5.6

Rpm-qa Mysql-server | grep mysql-server >/tmp/rpm.log

If [$?-eq 0];then

echo "You have installed ' Cat/tmp/rpm.log '"

echo "Enter Y/yes to continue, and other any key exits (Y/yes)"

Read INPUT1

if [[$input 1 = y]]; then

Yum-y Remov ' Cat/tmp/rpm.log '

echo "Start install MySQL5.6"

Else

if [[$input 1 = yes]]; then

yum-y remov ' Cat/tmp/rpm.log '

echo "Start install MySQL5.6"

Else

echo "The script has exit 1"

Exit 2

Fi

echo "The script has exit 2"

Exit 3

Fi

Else

echo "Start install MySQL5.6"

Fi



#检查mysql用户是否存在, does not exist then creates

Egrep "^ $User"/etc/passwd >&/dev/null

If [$?-ne 0];then

Useradd-s/sbin/nologin $User &>/dev/null

Fi

#安装libaio依赖包

echo "See Dependency installation Package"

Yum-y Install libaio* &>/dev/null

Rpm-qa libaio*


# download MySQL5.6 binary package decompression.

# wget $Mysql _url


If [-f $Mysql. tar.gz];then

echo "Unpack ... $Mysql. tar.gz"

TAR-XF $Mysql. tar.gz

Else

echo "$Mysql. tar.gz package does not exist"

Fi


Renamed Mysql #移动mysql -5.6.35-linux-glibc2.5-x86_64 to the $mysql_basedir/directory

If [-D $Mysql];then

echo "Move $Mysql Mysql"

MV $Mysql $Mysql _basedir/mysql

Else

echo "Unpack $Mysql. tar.gz on"

Fi

#移动datadir to $mysql_datedir

If [-D $Mysql _basedir/mysql/data];then

echo "Move $Mysql _basedir/mysql/data $Mysql _datedir"

MV $Mysql _basedir/mysql/data $Mysql _datedir

Else

echo "$Mysql _basedir/mysql/data non-existent"

Fi

#检查 $Mysql _datedir exists and is licensed to Mysql.

If [-D $Mysql _datedir/data];then

Chown-r Mysql.mysql $Mysql _datedir/data

Chown-r Mysql.mysql $Mysql _basedir/mysql

Else

echo "$Mysql _datedir/data non-existent"

Fi



#初始化MySQL

$Mysql _basedir/mysql/scripts/mysql_install_db--datadir= $Mysql _datedir--basedir= $Mysql _basedir/mysql--user=$ User--explicit_defaults_for_timestamp

If [$?-eq 0];then

echo "Initialization MySQL OK"

Else

echo "Initialization MySQL NO"

Exit 4

Fi


#拷贝启动脚本 ....

if [!-f/etc/init.d/mysqld];then

CP $Mysql _BASEDIR/MYSQL/SUPPORT-FILES/MYSQL.SERVER/ETC/INIT.D/MYSQLD

Else

RM-RF/ETC/INIT.D/MYSQLD && CP $Mysql _BASEDIR/MYSQL/SUPPORT-FILES/MYSQL.SERVER/ETC/INIT.D/MYSQLD

Fi



echo "$Mysql _basedir/mysql/lib" >/etc/ld.so.conf.d/mysql.conf

If [$?-eq 0];then

echo "Mysql Lib OK"

Fi


Ln-s $Mysql _basedir/mysql/include/usr/include/mysql

Ln-s $Mysql _basedir/mysql/bin/*/usr/bin/


#Config my.cnf

Mv/etc/my.cnf/etc/my.cnf.ori

echo "" >/etc/my.cnf


echo "[Mysqld]

user = $User

Port = 3306

Server-id = $ip 2

Basedir = $Mysql _basedir/mysql

DataDir = $Mysql _datedir

">/etc/my.cnf



$Mysql _basedir/mysql/bin/mysql-e "DROP database test;drop User [email protected] ':: 1 ';d ROP user ' @ ' localhost ';d rop User ' @ ' localhost.localdomain ';d rop user ' root ' @ ' localhost.localdomain '; Select User,host from Mysql.user;flush privileges; "

Sleep 1

/usr/local/mysql/bin/mysqladmin-uroot password ' [email protected] '


Chkconfig mysqld on


Service mysqld Start


Netstat-anput | grep mysqld


Pid= ' Netstat-anput |  grep mysqld | Awk-f ' [;] + ' {print $7} ' |awk-f ' [/]+ ' {print '} '

Port= ' Netstat-anput |  grep mysqld | Awk-f ' [;] + ' {print $4} ' | Awk-f ' [:;] + ' {print $} '


echo "PID $Pid"

echo "PROT $Port"

---------

Can be copied directly using

# wget $Mysql _url If you do not have a MySQL installation file locally, you can cancel the previous comment and download the MySQL binary installation package automatically.


Automatic installation of MySQL5.6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.