www.colben.cn/content/post/mariadb-install.md
2022-03-28 19:50:06 +08:00

86 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "CentOS 安装官方编译的 Mariadb 10.1 二进制通用包"
date: 2019-10-30T17:53:33+08:00
lastmod: 2019-10-30T17:53:33+08:00
tags: ["centos", "mariadb", "二进制"]
categories: ["database"]
---
## 环境
- centos 5.4/6.2/6.5/7.2 x86_64
## 安装
1. 下载官方编译好的 linux 通用安装包,解压之自定义目录(如/opt
```bash
# rhel 7 地址:
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.1.19/bintar-linux-glibc_214-x86_64/mariadb-10.1.19-linux-glibc_214-x86_64.tar.gz
# rhel 5/6 地址:
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.1.19/bintar-linux-x86_64/mariadb-10.1.19-linux-x86_64.tar.gz
tar zxf mariadb-10.1.19-linux*-x86_64.tar.gz -C /opt/
cd /opt
mv mariadb-10.1.19-linux* mariadb
```
2. 创建服务文件和配置文件,创建日志目录
```bash
cd /opt/mariadb
mv support_files/my-large.cnf ./my.cnf
mv support_files/mysql.server ./mysqld
mkdir -p log
```
3. 修改服务文件 mysqld
```
vim /opt/mariadb/mysqld
# 在打开的文件中修改开头的basedir和datadirdatadir是数据库文件目录建议指定一个大分区中的目录
basedir=/opt/mariadb
datadir=/mnt/sdb1/mariadb_db
# 修改开头的lockdir和lock-file-path
lockdir='/opt/mariadb/log'
lock-file-path="$lockdir/mysql.lock"
```
4. 修改配置文件 /opt/mariadb/my.cnf
```ini
[mysqld]
datadir=/mnt/sdb1/mariadb_db
log-error=/opt/mariadb/log/error.log
pid-file=/opt/mariadb/log/mysql.pid
user = mysql
#port = 3306
socket = /tmp/mysql.sock
skip-networking # 取消监听端口,适合本地数据库使用
skip-name-resolve # 取消域名解析
max-connections = 3000
max-connect-errors = 1000
#如果系统中存在 /etc/my.cnf 且不可写, 可以在 /opt/mariadb/my.cnf 中重新设置冲突项。
```
5. 修改数据库程序数据目录的权限:
```bash
chown mysql.mysql /opt/mariadb/ -R
chown mysql.mysql /mnt/sdb1/mariadb_db/ -R
```
6. 安装数据库
```bash
/opt/mariadb/scripts/mysql_install_db --basedir=/opt/mariadb --datadir=/mnt/sdb1/mariadb_db --user=mysql
```
7. 根据提示修改mariadb的root帐号密码禁用root登陆删除匿名用户及test库
```bash
# 启动 mariadb
/opt/mariadb/mysqld start
# 修改 root 密码
/opt/mariadb/bin/mysqladmin -u root password '12345678'
# 安全设置
/opt/mariadb/bin/mysql_secure_install --basedir=/opt/mariadb
```
8. 增加系统动态库配置
```bash
echo '/opt/mariadb/lib' >> /etc/ld.so.conf
ldconfig
```