mysql一键安装_自动化运维——一键安装MySQL

#!/bin/bash

#created by Kevin2016/03/30, modify 2016/04/20#-----------------------------------------------------------------------------# Installation Scriptfor the auto-deployment EMM(Linux edition)

#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# shell script toinstall MySQL (default version mysql-community-5.7.11)echo "-----------------------start install mysql----------------------"# Add to mysql user and mysql groupif [ `grep "mysql" /etc/passwd | wc -l` -eq 0 ];then

echo "adding user mysql"groupadd mysql

useradd-r -g mysql mysqlelse

echo "mysql user is exist"

fi# check installed mysql or notfor i in `rpm -qa | grep "mysql"`dorpm-e --allmatches $i --nodepsdone# Remove pre-installed on OS MariaDB ifexistsfor i in $(rpm -qa | grep mariadb | grep -v grep)do

echo "Deleting rpm -->"$i

rpm-e --nodeps $idone# Install mysqlserver

rpm-ivh mysql-community-server-5.7.11-1.el7.x86_64.rpm mysql-community-client-5.7.11-1.el7.x86_64.rpm mysql-community-common-5.7.11-1.el7.x86_64.rpm mysql-community-libs-5.7.11-1.el7.x86_64.rpm

# check the installtation was successful or not

rpm-qa |grep "mysql"

if [ $? != 0 ];then

echo "mysql install fail"| tee$mysql_instlog

exit1

else

echo "mysql isntall success"| tee$mysql_instlogfi# modify configuration files

cd/etc/

echo "character_set_server=utf8" >>my.cnf

# startup the mysql

systemctl start mysqld

systemctl status mysqld/etc/init.d/mysqld start/etc/init.d/mysqld stopecho "MySQL Server install successfully!"# configurationcat /etc/my.cnfsed -i '/mysqld/a\skip-grant-tables' /etc/my.cnf

systemctl restart mysqld

# mysql-u root mysql

mysql-u root mysql -e "use mysql;"# use mysql

# update mysql.user set authentication_string=password('root') where user='root';

mysql-u root mysql -e "update mysql.user set authentication_string=password('root') where user='root' ;"mysql-u root mysql -e "flush privileges;"

cat /etc/my.cnfsed -i '/skip-grant-tables/s/^/#/' /etc/my.cnf

# mysql-u root -p

# SET PASSWORD= PASSWORD('root');

mysql-u root -proot --connect-expired-password -e "SET PASSWORD = PASSWORD('root');"# mysql-u root mysql

# use mysql;

mysql-u root -proot -e "use mysql;"# update user set host= '%' where user ='root';

mysql-u root -proot -e "update user set host = '%' where user ='root';"#selecthost, user from user;

mysql-u root -proot -e "select host, user from user;"# exit

mysql-u root -proot -e "source /usr/src/tools/user.sql;"mysql-u root -proot -e "source /usr/src/tools/emm_saas_base.sql;"# create a new database, name as"emm_saas_base"# mysql-u root -p

# create database emm_saas_base;

# mysql-u root -proot -e "create database emm_saas_base;"# show databases;

# mysql-u root -proot -e "show databases;"# initdb

#for x in find . -name "*.sql"#dosource emm_saas_base.sql

#done# create user&authentication

# mysql-u root -p

# CREATE USER'emm'@'%' IDENTIFIED BY 'emm';

# GRANT ALL ON*.* TO 'emm'@'%';

# show userinthe DB

#selecthost,user from mysql.user;

mysql-u root -proot -e "select host,user from mysql.user;"

echo "The MySQL install and config complete!"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值