CentOS7.0通过Shell脚本一键安装Mysql

2020-5-18 20:31

安装脚本

以下是Shell脚本:

#!/bin/bash
# author: 赵利文 微信ID:zhaoliwen89
# 首先检测rpm安装包是否准备好
#  1.MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm
#  2.MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm
if test -e ./MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm;then
	echo "mysql-server file check ok."
else
	echo "当前目录MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm 不存在!请先下载"
 	exit 1
fi
if test -e MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm;then
	echo "mysql-client file check ok."
else
	echo "当前目录MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm 不存在!请先下载~"
 	exit 1
fi

#创建mysql用户组以及mysql用户
groupadd mysql
if [ $? == 0 ];then
	echo "create group mysql success"
else
	echo "create group mysql error"
fi
useradd -r mysql
if [ $? == 0 ];then
	echo "create user mysql success"
else
	echo "create user mysql error"
fi


# 删除冲突的依赖包
yum -y remove mariadb-libs

# 安装服务器端
echo "正在安装Mysql服务端"
rpm -i MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm
installResault=$?
#sleep 30
if [ $installResault == 0 ];then
	echo "Mysql服务器端安装成功"
fi


# 安装mysql客户端
echo "正在安装Mysql客户端"
rpm -i MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm
installResault=$?
#sleep 30
if [ $installResault == 0 ];then
	echo "Mysql客户端安装成功"
fi


cp /usr/share/mysql/mysql.server /etc/init.d/mysqld

chown -R  mysql:mysql /var/lib/mysql

#启动mysql服务
service mysqld start 


保存之后,执行就可以了。

其它

初始密码保存在:/root/.mysql_secret
修改mysql密码:set password for root@localhost=password(“xxx”)

你可能感兴趣的:(互联网)