RedHat7上安装MariaDB
编译安装MariaDB
- 下载MariaDB
# wget http://mirrors.opencas.cn/mariadb//mariadb-10.1.8/source/mariadb-10.1.8.tar.gz - 解压缩MariaDB
# tar -zxvf mariadb-10.1.8.tar.gz && cd mariadb-10.1.8 - 安装依赖软件
# yum -y install gcc-c++ cmake ncurses-devel bison libxml2-devel openssl-devel - 编译安装MariaDB
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
如果编译出错,需先删除CMakeCache.txt,然后安装依赖软件后,重新编译
# make && make install - 创建mysql用户及用户组
# useradd -r -M -s /sbin/nologin mysql - 创建MariaDB数据目录并修改属组
# mkdir -p /data/mysql && chown -R mysql:mysql /data/mysql/ - 根据服务器性能,拷贝相对应的MariaDB配置文件
# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf - 安装MariaDB数据库
# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql - 创建MariaDB启动脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld - 设置MariaDB服务开机自启动
# chmod +x /etc/init.d/mysqld
# chkconfig mysqld on - 启动MariaDB服务
# service mysqld start - 设置MariaDB系统变量
# echo "export PATH=\$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysqld.sh
# source /etc/profile.d/mysqld.sh - 初始化MariaDB安全配置
# mysql_secure_installation
备注:
编译参数列表
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DMYSQL_USER=mysql \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STPRAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWIYH_READLINE=1 \ -DWIYH_SSL=system \ -DVITH_ZLIB=system \ -DWITH_LOBWRAP=0 \ -DMYSQL_TCP_PORT=3306 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci
如果想要指定MariaDB安装位置和数据目录位置,可以修改 /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
yum安装MariaDB
- 添加MariaDB repo
# vi /etc/yum.repo.d/MariaDB.repo
# MariaDB 10.1 CentOS repository list - created 2015-12-05 04:46 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
- 安装mariaDB
# yum -y install MariaDB-server MariaDB-client - 设置MariaDB服务开机自启动
# systemctl enable mariadb - 启动MariaDB服务
# systemctl start mariadb - 初始化MariaDB安全配置
# mysql_secure_installation
创建mysql用户及用户组