linux 免安装数据库,免安装执行mysql,并且导入数据库(Linux)

#!/bin/bash

MYSQL_VERSION='mysql-5.5.32-linux2.6-i686'

MYSQL_PACKAGE='mysql-5.5.32-linux2.6-i686.tar.gz'

LIBAIO_PACKAGE='libaio-0.3.106-5.i386.rpm'

LOCK_FILE='wot.lock'

CURRENT_DIR=$(cd "$(dirname $0)"; pwd)

############################################

function isStartSuccess()

{

count=10

isSuccess=0

while [ $count -lt 0 ]

do

count=$(count - 1)

run_status=$(ps -ef | grep -v 'grep' | egrep "bin/mysqld_safe --user=mysql")

if [ "${run_status}X" -eq "X" ];then

echo "check mysql service,please wait..."

else

break

fi

isSuccess=1

sleep 1

done

if [ "${isSuccess}" == 0 ];then

echo "Mysql start success...."

exit 0

else

echo "Mysql start fail...."

exit 1

fi

}

function shutdownMysql()

{

bin/mysqladmin -uroot -proot shutdown >/dev/null 2>&1

pids=$(ps -ef | grep -e "bin/mysqld_safe" | grep -v grep | awk '{print $2}')

for pid in $pids

do

kill -9 $pid

done

pids=$(ps -ef | grep -e "bin/mysqld" | grep -v grep | awk '{print $2}')

for pid in $pids

do

kill -9 $pid

done

pids=$(ps -ef | grep -e "\[mysqld\]" | grep -v grep | awk '{print $2}')

for pid in $pids

do

kill -9 $pid

done

}

###############################################

#check libaio lib

isExistLibaio=$(rpm -qa | grep libaio)

if [ "${isExistLibaio}X" == "X" ];then

echo "Libaio library is not install,we will install it,please wait."

rpm -ivh $CURRENT_DIR/$LIBAIO_PACKAGE

fi

if [ -e "$CURRENT_DIR/$MYSQL_VERSION/$LOCK_FILE" ];then

echo starting mysql,please waiting...

cd "$CURRENT_DIR/$MYSQL_VERSION"

#start mysql

shutdownMysql

sleep 5

/bin/bash "bin/mysqld_safe" --user=mysql &

isStartSuccess

fi

echo "Mysql first install to you PC.please wait..."

rm -fr $CURRENT_DIR/$MYSQL_VERSION

tar -zxf "$CURRENT_DIR/$MYSQL_PACKAGE"

echo starting mysql,please waiting...

cd "$CURRENT_DIR/$MYSQL_VERSION"

#modify perm

chmod -R 744 bin

chmod -R 744 scripts

#check mysql folder

if [ -e /usr/local/mysql ];then

echo "Other Mysql is installed.please uninstall it and remove /usr/local/mysql"

exit 1

else

rm -fr /usr/local/mysql >/dev/null 2>&1

ln -s "$CURRENT_DIR/$MYSQL_VERSION" /usr/local/mysql

fi

#check mysql user and group

groupid=`grep 'mysql' /etc/group|awk -F : '{print $3}'`

if [ ! -z $groupid ] ;then

echo "Mysql group is exist."

else

groupadd mysql

fi

userid=`grep 'mysql' /etc/passwd|awk -F : '{print $3}'`

if [ ! -z $userid ] ;then

echo "Mysql user is exist."

else

useradd -g mysql mysql

fi

#check my.cnf

if [ -e /etc/my.cnf ] ;then

cp /etc/my.cnf /etc/my.cnf.other

fi

cp "$CURRENT_DIR/$MYSQL_VERSION/support-files/my-large.cnf" /etc/my.cnf

#modify mysql perm

chown -R mysql:mysql "$CURRENT_DIR/$MYSQL_VERSION"

chmod -R 744 bin

#install mysql script

/bin/bash "scripts/mysql_install_db" --user=mysql

shutdownMysql

bin/mysqld_safe &

sleep 5

#modify root password

bin/mysqladmin -uroot password root

shutdownMysql

bin/mysqld_safe --user=mysql&

sleep 5

#import sql data

if [ -e "$CURRENT_DIR/platform_core.sql" ];then

echo "Import platform_core.sql,please wait..."

bin/mysql -uroot -proot -hlocalhost

fi

#start mysql

shutdownMysql

sleep 5

/bin/bash "bin/mysqld_safe" --user=mysql&

#lock mysql

touch $LOCK_FILE

isStartSuccess

实施的步骤

1.解压包

2.初始化数据库脚本

3.修改密码

4.导入sql语句

5.启动mysql

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值