默认软件包在当前目录下。执行该脚本即可。
#!/bin/bash #------------------------------------------ #Filename:mariadb.sh #Revision:1.0 #Date:2017-10-11 #Author:zhangsan #Email:798761864@qq.com #http://www.ardusty.com/ #boke://amelie.blog.51cto.com/ #Description: #------------------------------------------ #定义版本变量 ver=`cat/etc/redhat-release|grep-o[0-9]|head-n1` #初始化安装环境 [$ver-eq7]&&{yumremovemariadb-y&>/dev/null;} [$ver-eq6]&&{yumremoveMysqL-y&>/dev/null;} pkill-9-UMysqL&>/dev/null userdel-rMysqL&>/dev/null #创建系统用户 useradd-d/app/MysqLdb-r-m-s/sbin/nologinMysqL #解压缩到指定文件夹,创建软链接 file=`cd;lsmariadb-*` cd;tarxf$file-C/usr/local/&>/dev/null cd/usr/local file1=`lsmariadb-*-d` rm-rfMysqL&>/dev/null ln-s$file1MysqL #配置配置文件 mkdir/etc/MysqL&>/dev/null cp/usr/local/MysqL/support-files/my-huge.cnf/etc/MysqL/my.cnf sed-r-i"/^\[MysqLd\]/s/.*/[MysqLd]\ndatadir=\/app\/MysqLdb\ninnodb_file_per_table=on\nskip_name_resolve=on\n/"/etc/MysqL/my.cnf cd/usr/local/MysqL/ ./scripts/MysqL_install_db--user=MysqL--datadir=/app/MysqLdb&>/dev/null #启动服务 cp/usr/local/MysqL/support-files/MysqL.server/etc/init.d/MysqLd chkconfig--addMysqLd [$ver-eq7]&&{mkdir/var/log/mariadb&>/dev/null;touch/var/log/mariadb/mariadb.log;chownMysqL/var/log/mariadb/mariadb.log;chownMysqL/var/log/mariadb;} [$ver-eq6]&&{touch/var/log/MysqLd.log;chownMysqL/var/log/MysqLd.log;} serviceMysqLdstart&>/dev/null #PATH变量及安全环境初始化 echo'PATH=/usr/local/MysqL/bin:$PATH'>/etc/profile.d/MysqL.sh echo-e"\ny\nmagedu\nmagedu\ny\nn\nn\n\y\n"|/usr/local/MysqL/bin/MysqL_secure_installation&>/dev/null原文链接:https://www.f2er.com/centos/375622.html