运维辞典@欢迎访问小站,如有疑问,可通过右侧QQ或底部邮箱联系,非常感谢@

cmake方式编译安装MariaDB数据库

MariaDB Administrator 349℃

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB。 MariaDB由MySQL的创始人Michael Widenius(英语:Michael Widenius)主导开发,他早前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。MariaDB名称来自Michael Widenius的女儿Maria的名字。
MariaDB基于事务的Maria存储引擎,替换了MySQL的MyISAM存储引擎,它使用了Percona的 XtraDB,InnoDB的变体,分支的开发者希望提供访问即将到来的MySQL 5.4 InnoDB性能。这个版本还包括了 PrimeBase XT (PBXT) 和 FederatedX存储引擎。

cmake方式编译安装MariaDB数据库

#!/bin/bash
# 通过cmake方式编译安装MariaDB数据库
# 要求:cmake版本高于等于2.8.2
# site:www.724001.com
# 错误解决:
# https://www.cnblogs.com/ityunv/p/5909485.html
# http://blog.csdn.net/tuenbotuenbo/article/details/38365885
# http://www.linuxidc.com/Linux/2017-02/140344.htm
#

MariaDB_VER=10.2.11
MariaDB_ROOT_PASS=root3306
DOWN_ADDR=http://192.168.6.188/down
DOWN_TMP_DIR=/tmp/downloads
RUN_DIR=/usr/local/src
ExecutionTime=`date +%Y%m%d%H%M`
CPU_NUM=`cat /proc/cpuinfo | grep processor | sort -u | wc -l`
OS_VER=6
grep -q "release 6" /etc/redhat-release && OS_VER=6
grep -q "release 7" /etc/redhat-release && OS_VER=7
if [[ `uname -m` == x86_64 ]]; then
	OS_BIT=64
elif [[ `uname -m` == i386 ]]; then
	OS_BIT=32
else
	echo "Err.OSBIT"
fi
 
function EchoRed(){
	echo -e "\033[31m $1 \033[0m"
	exit 1
}
function EchoYellow(){
	echo -e "\033[33m $1 \033[0m"
}
function EchoGreen(){
	echo -e "\033[32m $1 \033[0m"
}
 
[ "$UID" -ne 0 ] && EchoRed "Must be root to run this script."
 
function GetURL(){
MariaDB_DOWN_URL=$DOWN_ADDR/mariadb/mariadb-$MariaDB_VER.tar.gz
}
GetURL
 
# CheckPort 3306
function CheckPort(){
	yum -y install lsof
	lsof -i :$1
	if [ $? == 0 ]; then
		EchoRed "Port $1 already and exists."
	fi
}
 
function checkOK(){
	if [[ $? -ne 0 ]]; then
		EchoRed "Error,shell exit.Error Position:$1"
	fi
}
 
# DOWN_URL=$PHP_DOWN_URL && FileNotFoundWget php-$PHP_VER.tar.gz
function FileNotFoundWget(){
	mkdir -p $DOWN_TMP_DIR && cd $DOWN_TMP_DIR
	[ -s $1 ] || wget $DOWN_URL -O $DOWN_TMP_DIR/$1
	checkOK "Wget $1 Error."
}
 
function ReYumURL(){
	/bin/mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.$ExecutionTime
	/bin/mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.$ExecutionTime
	if [[ $OS_VER == 6 ]]; then
		wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo || curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
		wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo || curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
	elif [[ $OS_VER == 7 ]]; then
		wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo || curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
		wget -O /etc/yum.repos.d/epel.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo || curl -o /etc/yum.repos.d/epel.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
	fi
	yum clean all
	yum makecache
}
function InstallMariaDB(){
	CheckPort 3306
	useradd mysql -s /sbin/nologin -M
	yum -y install cmake gcc gcc-c++ ncurses-devel openssl-devel
	# wget http://192.168.6.188/down/mariadb/mariadb-10.2.11.tar.gz
	DOWN_URL=$MariaDB_DOWN_URL && FileNotFoundWget mariadb-$MariaDB_VER.tar.gz
	tar zxvf mariadb-$MariaDB_VER.tar.gz
	cd mariadb-$MariaDB_VER
	rm -f CMakeCache.txt
	cmake -DCMAKE_INSTALL_PREFIX=$RUN_DIR/mariadb-$MariaDB_VER -DMYSQL_DATADIR=$RUN_DIR/mariadb-$MariaDB_VER/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
	checkOK "CMake_MariaDB Error."
	make -j $CPU_NUM
	checkOK "InstallMariaDB_Make Error."
	make install
	checkOK "InstallMariaDB_Make_Install Error."
	$RUN_DIR/mariadb-$MariaDB_VER/scripts/mysql_install_db --basedir=$RUN_DIR/mariadb-$MariaDB_VER/ --datadir=$RUN_DIR/mariadb-$MariaDB_VER/data/
	chown mysql.mysql $RUN_DIR/mariadb-$MariaDB_VER/data/ -R
	/bin/cp $RUN_DIR/mariadb-$MariaDB_VER/support-files/mysql.server /etc/init.d/mysqld
	/bin/cp $RUN_DIR/mariadb-$MariaDB_VER/support-files/my-medium.cnf /etc/my.cnf
	if [[ $OS_VER == 6 ]]; then
		service mysqld start
		chkconfig mysqld on
	elif [[ $OS_VER == 7 ]]; then
		systemctl enable mysqld
		systemctl start mysqld
	fi
	ln -s $RUN_DIR/mariadb-$MariaDB_VER/bin/* /usr/bin/
}
function SetPassAndDelInfo(){
	$RUN_DIR/mariadb-$MariaDB_VER/bin/mysqladmin -u root password "$MariaDB_ROOT_PASS"
	$RUN_DIR/mariadb-$MariaDB_VER/bin/mysql -uroot -p"$MariaDB_ROOT_PASS" -A -e "drop database test;"
	$RUN_DIR/mariadb-$MariaDB_VER/bin/mysql -uroot -p"$MariaDB_ROOT_PASS" -A -e "use mysql;delete from user where password=\"\";"
}

EchoGreen "================MariaDB版本$MariaDB_VER安装 ==========="
sleep 1
InstallMariaDB
SetPassAndDelInfo
EchoGreen "================MariaDB版本$MariaDB_VER ==========="
EchoGreen "MariaDB $MariaDB_VER 目录及配置文件:"
EchoGreen "安装目录:$RUN_DIR/mariadb-$MariaDB_VER/"
EchoGreen "配置文件路径:/etc/my.cnf"
EchoGreen "数据文件目录:$RUN_DIR/mariadb-$MariaDB_VER/data/"
EchoGreen "mysql数据库root用户密码:$MariaDB_ROOT_PASS"

码字很辛苦,转载请注明来自:《运维辞典 » cmake方式编译安装MariaDB数据库

喜欢 (1)