1.修改系统自带yum源为阿里yum源
cd /etc/yum.repos.d
mkdir bak
mv CentOS* ./bak/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2.卸载Centos系统自带的低版本Mariadb数据库
yum remove mariadb-*
3.创建Mariadb数据库的yum仓库
在目录下 /etc/yum.repos.d/ 创建文件: MariaDB.repo
vim /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
gpgkey = http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
4.清楚yum缓存并重新建立yum库
yum clean all
yum makecache
5.安装MariaDB数据库
yum install MariaDB-client MariaDB-server MariaDB-devel -y
6.修改数据库配置文件
vi /etc/my.cnf.d/server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-external-locking
#innodb_autoinc_lock_mode=0
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# 并发线程数,建议为CPU核心数乘以2: CPU's*2 for thread_concurrency
thread_concurrency = 8
innodb_purge_threads = 8
max_connections=200
7.启动Mariadb数据库并设为开机自启
systemctl start mariadb
systemctl enable mariadb
8.初始化Mariadb数据库
/usr/bin/mysql_secure_installation
Enter current password for root (enter for none): Just press the Enter button //回车
Set root password? [Y/n]: Y //设置root密码
New password: your-MariaDB-root-password
Re-enter new password: your-MariaDB-root-password
Remove anonymous users? [Y/n]: Y //删除初始用户
Disallow root login remotely? [Y/n]: n //禁止root远程登录
Remove test database and access to it? [Y/n]: Y //删除test库
Reload privilege tables now? [Y/n]: Y //刷新表
//初始化完成后重启数据库
8.附带Mariadb数据库压力测试命令
mysqlslap -a -c 500 -i 10 -uroot -p
9.数据库用户授权命令
grant all on *.* to 'test_1'@'localhost' identified by '123456';