Step.1 清理自带环境
[root@deploy ~]# rpm -qa| grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@deploy ~]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
Step.2 安装依赖库文件
[root@deploy ~]# yum install -y libaio-devel
Step.3 新建mysql用户和组
[root@deploy ~]# useradd -s /sbin/nologin -M mysql
Step.4 解压二进制安装包至/usr/local
[root@deploy ~]# tar xf mariadb-10.3.22-linux-systemd-x86_64.tar.gz -C /usr/local/
Step.5 创建软链接
[root@deploy ~]# ln -s /usr/local/mariadb-10.3.22-linux-systemd-x86_64/ /usr/local/mysql
Step.6 设置目录权限
[root@deploy ~]# chown -R mysql.mysql /usr/local/mysql/
Step.7 设置环境变量
[root@deploy ~]# cat > /etc/profile.d/MariaDB.sh << EOF
#!/bin/bash
export PATH=/usr/local/mysql/bin:\$PATH
EOF
[root@deploy ~]# source /etc/profile.d/MariaDB.sh
Step.8 MariaDB配置文件
[root@deploy ~]# cat > /etc/my.cnf << EOF
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
EOF
Step.9 创建MariaDB数据目录
[root@deploy ~]# mkdir -p /data/mysql
[root@deploy ~]# chown -R mysql.mysql /data/mysql/
[root@deploy ~]# /usr/local/mysql/scripts/mysql_install_db
Installing MariaDB/MySQL system tables in '/data/mysql' ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h mariadb01 password 'new-password'
Alternatively you can run:
'./bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql'
You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
Step.10 创建MariaDB自启动脚本,并加入开机启动
[root@deploy ~]# cp /usr/local/mysql/support-files/systemd/mariadb.service /usr/lib/systemd/system/
[root@deploy ~]# systemctl enable --now mariadb
Step.11 MariaDB设置安全脚本
[root@deploy ~]# mysql_secure_installation
Enter current password for root (enter for none): #回车键
Change the root password? [Y/n] y #更改root密码
Remove anonymous users? [Y/n] y #删除匿名用户
Disallow root login remotely? [Y/n] n #禁止远程root登录
Remove test database and access to it? [Y/n] y #删除测试数据库
Reload privilege tables now? [Y/n] y #重新加载特权表
Step.12 启动数据库
[root@deploy ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.22-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)