centos

CentOS数据库安装步骤

小樊
44
2025-10-19 23:28:09
栏目: 智能运维

一、安装前准备

二、MySQL数据库安装步骤

1. 添加MySQL YUM仓库

下载MySQL官方YUM仓库包(以MySQL 8.0为例):
sudo yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
(CentOS 8及以上版本替换为对应仓库包,如el8)。

2. 安装MySQL服务器

更新YUM缓存并安装MySQL:
sudo yum makecache fast && sudo yum install -y mysql-community-server

3. 启动与开机自启

启动MySQL服务:sudo systemctl start mysqld
设置开机自启:sudo systemctl enable mysqld

4. 安全配置
5. 验证安装

三、PostgreSQL数据库安装步骤

1. 添加PostgreSQL YUM仓库

下载PostgreSQL官方YUM仓库包(以PostgreSQL 13为例):
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
(CentOS 8及以上版本替换为EL-8-x86_64)。

2. 安装PostgreSQL服务器

安装PostgreSQL及扩展组件:
sudo yum install -y postgresql13-server postgresql13-contrib

3. 初始化数据库

运行初始化脚本(CentOS 7及以上使用systemd):
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb

4. 启动与开机自启

启动PostgreSQL服务:sudo systemctl start postgresql-13
设置开机自启:sudo systemctl enable postgresql-13

5. 配置访问权限(可选)
6. 验证安装

四、后续操作建议

0
看了该问题的人还看了