一键安装mysql
Posted 牵牛花
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一键安装mysql相关的知识,希望对你有一定的参考价值。
#!/bin/bash # # Rrogram: # install mysql # History: # 2017-10-05 luoqi v0.1 release # email: # 916790942@qq.com #以下rpm包需要自己下载并和该脚本放在同一目录下 #mysql-community-server-5.7.19-1.el7.x86_64.rpm mysql-community-client-5.7.19-1.el7.x86_64.rpm mysql-community-common-5.7.19-1.el7.x86_64.rpm #mysql-community-libs-5.7.19-1.el7.x86_64.rpm # # dependence yum -y install perl yum -y install -y perl-Module-Install.noarch yum -y install net-tools #created by Kevin 2016/03/30, modify 2016/04/20 # ----------------------------------------------------------------------------- # Installation Script for the auto-deployment EMM(Linux edition) # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # shell script to install MySQL (default version mysql-community-5.7.19) echo "-----------------------start install mysql----------------------" # Add to mysql user and mysql group if [ `grep "mysql" /etc/passwd | wc -l` -eq 0 ];then echo "adding user mysql" groupadd mysql useradd -r -g mysql mysql else echo "mysql user is exist" fi # check installed mysql or not for i in `rpm -qa | grep "mysql"` do rpm -e --allmatches $i --nodeps done # Remove pre-installed on OS MariaDB if exists for i in $(rpm -qa | grep mariadb | grep -v grep) do echo "Deleting rpm --> "$i rpm -e --nodeps $i done # Install mysqlserver rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm mysql-community-client-5.7.19-1.el7.x86_64.rpm mysql-community-common-5.7.19-1.el7.x86_64.rpm mysql-community-libs-5.7.19-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 exit 1 else echo "mysql isntall success"| tee $mysql_instlog fi # 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 stop echo "MySQL Server install successfully!" # configuration cat /etc/my.cnf sed -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.cnf sed -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‘);" echo "install successfully!!" # exit
https://dev.mysql.com/downloads/mysql/ 下载mysql
以上是关于一键安装mysql的主要内容,如果未能解决你的问题,请参考以下文章