简化安装mysql的安装过程,局限很大,仅支持centos7.6上安装mysql5.5.60,如果想在其他版本的操作系统安装mysql,请自行修改有关变量。
如果想了解mysql安装的具体过程,请参考以下链接,写的非常详细!
https://blog.csdn.net/qq_35197601/article/details/83542498
1、操作系统版本centos7.6
2、mysql的版本mysql5.5.60(mysql安装包:mysql-5.5.60-linux-glibc2.12-x86_64.tar.gz)。
1、到mysql官网下载相应版本的mysql包(mysql的包要求和脚本里面的一致,否则请自行修改该变量)
2、上传mysql_install.sh脚本和mysql安装包到/root目录,并执行脚本bash mysql_install.sh,即可!
#!/bin/bash #write by huangsonghai,Simplify mysql installation #V1.0 #2021-11-17 #step1、卸载系统的mariadb,创建mysql账户 echo -e "\033[31m myslq开始自动化安装,安装需要2-3分钟... \033[0m" rpm -e --nodeps `rpm -qa|grep mariadb` systemctl stop firewalld.service systemctl disable firewalld.service groupadd mysql useradd -g mysql mysql #step2、定义变量 package_way=/home/soft mkdir -p $package_way mysql_soft=`ls /root |grep mysql-5.5.60` #step3、解压软件包到指定位置 tar -zxvf /root/$mysql_soft -C $package_way tmp1=`ls $package_way` mv $package_way/$tmp1 $package_way/mysql #step4、开始安装mysql cp $package_way/mysql/support-files/my-medium.cnf /etc/my.cnf sed -i '/myisam_sort_buffer_size/a\'basedir=/home/soft/mysql'' /etc/my.cnf sed -i '/myisam_sort_buffer_size/a\'datadir=/home/soft/mysql/data'' /etc/my.cnf chown -R mysql:mysql $package_way/mysql/ $package_way/mysql/scripts/mysql_install_db --user=mysql --basedir=/home/soft/mysql/ --datadir=/home/soft/mysql/data/ chown -R mysql:mysql $package_way/mysql/data chown 777 /etc/my.cnf cp $package_way/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld chmod +x /etc/rc.d/init.d/mysqld chkconfig --add mysqld echo "export PATH=$PATH:/home/soft/mysql/bin" >> ~/.bash_profile && source ~/.bash_profile service mysqld start #step5、修改mysql信息 echo -e "\033[31m Mysql密码为空,请点击Enter键进入mysql: \033[0m" mysql -uroot -p -e " use mysql; update user set password=password('123456') where user='root' and host='localhost'; flush privileges; exit " #step6、重启mysql service mysqld restart service mysqld status num=`echo $?` if [ $num -eq 0 ];then echo -e "\033[32m mysql install successful \033[0m" else echo -e "\033[32m mysql install not successful,please check! \033[0m" fi