首頁>技術>

應粉絲要求,今天給大家分享一個超級實用的一鍵自動安裝部署Mysql的任意版本的指令碼!

指令碼用法:chmod 755 install-mysql.sh && sh install-mysql.sh 5.7.22 (後面跟的是你需要的版本號,需要什麼版本就寫什麼版本),我這裡安裝的5.7.22

指令碼內容展示如下:

#!/bin/sh# mysql 任何版本全程自動化原始碼編譯安裝# 用法:sh -x install-mysql.sh 5.7.22 後面跟的是你需要的版本號,需要什麼版本就寫什麼版本!version=$1usage(){echo "usage: $0 version"}if [ $# -ne 1 ]thenusageexit -1fiif [ -s /etc/my.cnf ];thenrm -rf /etc/my.cnffiecho "==================開始安裝 mysql ===================="yum install -y ncurses gcc gcc-c++ ncurses ncurses-devel openssl openssl-devel libtool* cmakemkdir -p /data/mysqlif [ 'grep "mysql" /etc/passwd | wc -l' ]; thenecho "adding user mysql"groupadd mysqluseradd -s /sbin/nologin -M -g mysql mysqlelseecho "mysql user 已存在!"fiecho "========================下載mysql===================="if [ ! -f mysql-${version}.tar.gz ]thenwget http://dev.mysql.com/get/Downloads/MySQL-${version}/mysql-${version}.tar.gzfiecho "========================解壓mysql安裝包================"tar -xvf mysql-${version}.tar.gzcd mysql-${version}echo "======================開始配置mysql===================="cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DENABLED_LOCAL_INFILE=1 \-DMYSQL_DATADIR=/var/mysql/data \-DWITH_BOOST=/usr/local/boost \-DMYSQL_USER=mysqlif [ $? -ne 0 ];thenecho "配置失敗,請檢查!!"exit 1fiecho "make mysql"makeif [ $? -ne 0 ];thenecho "make 失敗,請檢查!!"exit 1fimake installchown -R mysql:mysql /usr/local/mysqlchown -R mysql.mysql /data/mysql//usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqlchgrp -R mysql /usr/local/mysql/cp -f ./support-files/my-large.cnf /etc/my.cnfsed -i 's#^thread_concurrency = 8#& \ndatadir = /data/mysql#g' /etc/my.cnfcp ./support-files/mysql.server /etc/rc.d/init.d/mysqlchmod 755 /etc/init.d/mysqlln -s /usr/local/mysql/lib/mysql /usr/lib/mysqlln -s /usr/local/mysql/include/mysql /usr/include/mysqlln -s /usr/local/mysql/bin/mysql /usr/bin/mysqlln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldumpln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchkln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safeecho "mysql 啟動中---"/usr/local/mysql/bin/mysqld --user=mysqlif [ $? -ne 0 ];thenecho "mysql 啟動失敗,請檢查配置!"elseecho "mysql 啟動成功l!!"fi

注意:安裝高版本之前需要下載解壓boost軟體,因為需要boost庫的支援,不然後報錯。

1、在/usr/local下建立一個boost的資料夾,命令如下:

mkdir -p /usr/local/boost

2、進入這個新建立的資料夾然後下載boost

下載連結:wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz3、進行解壓就可以了,命令如下:

 tar -xvzf boost_1_59_0.tar.gz

開始安裝:

部署配置完成:

安裝完成後,可以登陸mysql資料庫並進行一些簡單的sql操作,如下圖所示:

10
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 如何解決生產環境 Flink 應用的技術難題?