1、关闭firewalld和SELinux
2、删除CentOS 7.6自带的MariaDB:
# rpm -qa | grep -i mariadb --> mariadb-libs-5.5.60-1.el7_5.x86_64
# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
3、如果之前安装过MySQL,也删除:# rpm -qa | grep -i mysql
4、删除之前MySQL的配置文件:# rm -rf /etc/my.cnf? # rm -rf /etc/my.cnf.d
5、安装编译时需要用到的开发工具软件包组:# yum -y groupinstall "Development Tools"
6、安装编译时需要用到的依赖软件包:
# yum -y install epel-release
# yum -y install zlib-devel libxml2-devel ncurses-devel bison-devel openssl-devel readline-devel libaio-devel boost-devel libcurl-devel libarchive-devel jemalloc-devel libevent-devel lvm2 bzip2-devel ntpdate
7、服务器时间同步
8、创建逻辑卷,用于存放MariaDB数据:
(1)虚拟机中新增一块10G的硬盘
(2)分区:# fdisk /dev/sdb --> n --> p --> 1 --> 回车 --> 回车 --> t --> 8e --> p --> w --> # partx -a /dev/sdb
(3)查看分区情况:# fdisk -l
(4)创建pv:# pvcreate /dev/sdb1? # pvs
(5)创建vg:# vgcreate data /dev/sdb1? # vgs
(6)创建lv:# lvcreate -l +100%FREE data -n mariadb? # lvs
(7)创建文件系统:# mke2fs -t ext4 /dev/data/mariadb
(8)创建挂载目录:# mkdir -pv /data
(9)开机自动挂载:# vim /etc/fstab --> /dev/data/mariadb /data ext4 defaults 0 0
(10)挂载分区:# mount -a? # mount
(11)查看磁盘使用情况:# df -Th
9、创建mariadb用户和组:
# groupadd -r mariadb
# useradd -r -s /sbin/nologin -g mariadb mariadb
# id mariadb
10、创建MariaDB安装目录:
# mkdir -pv /usr/local/mariadb-10.3.14
# chown -R mariadb.mariadb /usr/local/mariadb-10.3.14
11、在逻辑卷中创建MariaDB数据存放目录:
# mkdir -pv /data/mariadb
# chown -R mariadb.mariadb /data/mariadb
# chmod o-rx /data/mariadb
12、下载cmake,地址https://cmake.org/download/
13、编译安装cmake:
# tar -xf cmake-3.14.3.tar.gz -C /usr/src
# cd /usr/src/cmake-3.14.3
# ./bootstrap
# gmake && gmake install
# which cmake --> /usr/local/bin/cmake
# cmake --version
备注:yum方式安装的cmake版本为2.8.12
14、下载MariaDB 10.3,地址https://downloads.mariadb.org/mariadb/+releases/
15、编译安装MariaDB 10.3:
# tar -xf mariadb-10.3.14.tar.gz -C /usr/src
# cd /usr/src/mariadb-10.3.14
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb-10.3.14 -DMYSQL_DATADIR=/data/mariadb -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_ARIA_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_CONNECT_STORAGE_ENGINE=1 -DWITH_CSV_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_SEQUENCE_STORAGE_ENGINE=1 -DWITH_SPHINX_STORAGE_ENGINE=1 -DWITH_XTRADB_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DEXTRA_CHARSETS=all -DENABLE_PROFILING=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mariadb -DWITH_CURL=system -DWITH_DEBUG=0 -DWITH_LIBWRAP=0 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system
# make && make install
备注:
(1)./configure类似于cmake .? ./configure --help类似于cmake . -LH或ccmake .
(2)如果想清理此前编译生成的文件,使用命令# make clean和# rm -rf CMakeCache.txt
16、初始化MariaDB数据库:
# ll -lh /data/mariadb --> 空
# /usr/local/mariadb-10.3.14/scripts/mysql_install_db --user=mariadb --datadir=/data/mariadb
# ll -lh /data/mariadb
17、创建配置文件:
# cp /usr/local/mariadb-10.3.14/support-files/wsrep.cnf /etc/my.cnf
# vim /etc/my.cnf,在[mysqld]配置段中增加如下代码:
[mysqld]
port=3306
basedir=/usr/local/mariadb-10.3.14
datadir=/data/mariadb
socket=/tmp/mysql.sock
log-error=/var/log/mariadb.log
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
lower_case_table_names=1
innodb_file_per_table=1
skip_name_resolve=1
symbolic-links=0
18、编写unit文件:
# vim /usr/lib/systemd/system/mariadb.service
[Unit]
Description=MariaDB 10.3.14 database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=mariadb
Group=mariadb
ExecStart=/usr/local/mariadb-10.3.14/bin/mysqld_safe --datadir=/data/mariadb
TimeoutSec=300
PrivateTmp=false
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
19、启动MariaDB数据库:
# systemctl start mariadb.service
# ss -tunlp | grep 3306
# systemctl enable mariadb.service
# systemctl status mariadb.service
20、配置系统环境变量:
# vim /etc/profile.d/mariadb.sh --> export PATH=/usr/local/mariadb-10.3.14/bin:$PATH
# . /etc/profile.d/mariadb.sh
# echo $PATH
# mysql --version
21、MariaDB安全配置向导:# mysql_secure_installation
22、配置MariaDB库文件和头文件:
# vim /etc/ld.so.conf.d/mariadb.conf --> /usr/local/mariadb-10.3.14/lib
# ldconfig
# ln -sv /usr/local/mariadb-10.3.14/include /usr/include/mysql
23、授权用户远程登录:
# mysql -uroot -p
MariaDB> grant all on *.* to 'root'@'%' identified by '123456';
MariaDB> flush privileges;
24、使用客户端工具Navicat Premium远程连入MariaDB: