#!/bin/bash datadir="/mydata/data" sqlconf=/etc/mysql installdir=/usr/local/mysql # 关于安装包大家可以去官网下载,注意下载通用二进制格式的 ,然后放在ftp服务器上即可 # 此处假设我把mariadb5.5的安装包放在了ftp上的/pub/Sources/6.x86_64/mariadb下面 case $1 in 36) package=mariadb-5.5.36-linux-x86_64.tar.gz dir=mariadb-5.5.36-linux-x86_64 wget lftp 172.16.0.1:/pub/Sources/6.x86_64/mariadb/$package ;; 40) package=mariadb-5.5.40-linux-x86_64.tar.gz dir=mariadb-5.5.40-linux-x86_64 wget lftp 172.16.0.1:/pub/Sources/6.x86_64/mariadb/$package ;; *) echo "Usage /bin/bash `basename $0` 36|40" exit 1 esac #echo ‘get mariadb-5.5.36-linux-x86_64.tar.gz #bye ‘ | lftp 172.16.0.1:/pub/Sources/6.x86_64/mariadb tar xf ${package} -C /usr/local cd /usr/local # 为其创建链接mysql方便以后管理 ln -s ${dir} mysql cd ${installdir} #创建mysql系统用户 if ! id mysql &> /dev/null; then useradd -r mysql fi # 创建数据文件目录 if [ ! -d ${datadir} ]; then mkdir -pv ${datadir} &> /dev/null chown -R mysql:mysql ${datadir} fi # 初始化mariadb cd ${installdir} scripts/mysql_install_db --user=mysql --datadir=/mydata/data &> /dev/null # 为mariadb添加配置文件 if [ ! -d ${sqlconf} ]; then mkdir -p /etc/mysql &> /dev/null fi cd ${installdir} cp support-files/my-large.cnf /etc/mysql/my.cnf sed -i ‘/^thread_ca/a \datadir = /mydata/data \ninnodb_file_per_table = on \nskip_name_resolve = on‘ /etc/mysql/my.cnf # 为mariadb添加服务脚本 cp ${installdir}/support-files/mysql.server /etc/rc.d/init.d/mysqld chkconfig --add mysqld # 添加mariadb命令至PATH环境变量 echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh . /etc/profile.d/mysql.sh # 添加man手册 sed -i ‘/^MAN.*\/usr\/man/a MANPATH /usr/local/mysql/man/‘ /etc/man.config echo ‘The mariadb has installed successfully‘ echo ‘Please exect ". /etc/profile.d/mysql.sh" to update PATH‘
时间: 2024-11-10 19:59:33