centos7离线安装mariadb

1.概述

最近新接到一个项目,由于服务器不能通外网环境,许多环境需要离线安装。离线安装又分为rpm方式安装、二进制文件安装。rpm方式安装有时候需要一些系统包,有时候可能会有问题。二进制文件安装(安装包内包含所有依赖),解压即可使用。本文将介绍centos7环境下二进制文件安装mariadb。

2.安装流程

1.下载离线安装包
首先去mariadb官网下载安装包,根据需要版本进行下载,我这里下载10.2.29版本的:
centos7离线安装mariadb_第1张图片
2.解压安装包
安装包下载完成之后,上传到服务器上,进行解压:

#解压
tar -zxvf mariadb-10.3.38-linux-systemd-x86_64.tar.gz

#移动文件夹到/usr/local/mysql文件夹下
mv mariadb-10.3.38-linux-systemd-x86_64/ /usr/local/mysql

3.创建用户组

#添加mysql组
groupadd -g 3306 mysql

#添加用户到用户组
useradd -u 3306 -g 3306 -s /sbin/nologin mysql 

4.创建 mariadb 程序路径和数据路径

#创建mysql数据存储地方
mkdir -p /app/data/mysql

#创建日志存储
mkdir -p /app/data/log

5.文件夹赋权限

chown -R mysql:mysql /app/data

6.初始化 mariadb

#进入mysql文件夹
cd /usr/local/mysql

#执行初始化脚本
./scripts/mysql_install_db --user=mysql \
--basedir=/usr/local/mysql \
--datadir=/app/data/mysql

7.修改my.cnf初始配置
修改/etc/my.cnf

[client]
port = 3306
#配置socket
socket = /tmp/mysql.sock
[mysqld]
user = mysql
port=3306
[client]
port = 3306
#配置socket
socket = /tmp/mysql.sock
[mysqld]
user = mysql
port=3306
default-storage-engine = InnoDB
socket = /tmp/mysql.sock
skip-external-locking
character-set-server = utf8
max_allowed_packet = 16M
max_connect_errors=65535
skip_name_resolve = ON
sysdate-is-now = 1
innodb = FORCE
#数据存储位置
datadir = /app/data/mysql
log-bin = mysql-bin
auto_increment_increment=2
auto_increment_offset=2
log-slave-updates=on
binlog_format=mixed
max_binlog_size=1024M
binlog_cache_size = 2M
expire-logs-days = 14
server-id = 189
sync-binlog = 1
query-cache-type = 0
query-cache-size = 0
max_connections=8192
thread-cache-size = 1024
open_files_limit=8192
table-definition-cache = 1024
table-definition-cache = 1024
max_prepared_stmt_count=200000
slow_query_log=on
#慢查询日志
slow_query_log_file=/app/data/log/slow.log
#日志存储位置
log-error = /app/data/log/mysql-error.log
log-queries-not-using-indexes = 1
long_query_time = 1
interactive_timeout = 28800
wait_timeout = 28800
lower_case_table_names=1
innodb-log-file-size = 512M
innodb-flush-log-at-trx-commit = 2
innodb-file-per-table = 1
innodb-buffer-pool-size = 16G
innodb_log_buffer_size = 8M
innodb_lock_wait_timeout = 150
replicate-ignore-db = mysql
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
max_heap_table_size = 2048M
tmp_table_size = 2048M

10.修改启动文件

#进入mysql安装文件夹
cd /usr/local/mysql

#复制文件
cp -p support-files/mysql.server /etc/init.d/mysqld

#修改
vim /etc/init.d/mysqld

#主要修改路径变量的值
basedir=/usr/local/mysql
datadir=/data/mysql/db_file
mysqld_pid_file_path=/data/mysql/temp/mysqld.pid

11.启动并添加自启

#启动
service mysqld start
#添加自启
chkconfig --add mysqld
chkconfig mysqld on

12.配置全局路径

#进入profile文件
vim /etc/profile

#添加配置
export PATH=$PATH:/usr/local/mysql/bin

#更新配置
source /etc/profile

13.修改密码

/usr/local/mysql/bin/mysql_secure_installation

centos7离线安装mariadb_第2张图片
14.修改访问权限

#进入数据库
mysql -u root -p

//第一步:授权
grant all privileges on *.* to root@"%" identified by '123456' with grant option;
//第二步:刷新权限信息
flush privileges;

3.小结

1.本文介绍了centos7环境下mariadb的安装与配置,其实mysql的离线安装与Mariadb的安装类似,需要注意给文件夹赋权、修改主要文件路径等。

4.参考文献

1.https://mariadb.org/
2.https://mariadb.com/kb/en/getting-installing-and-upgrading-mariadb/

你可能感兴趣的:(数据库,mariadb,mysql,数据库)