在CentOS Minimal上安装数据库,你可以选择多种数据库系统,如MySQL、PostgreSQL或MariaDB等。以下是在CentOS Minimal上安装MySQL的步骤:
更新系统包
sudo yum update -y
安装MySQL服务器
sudo yum install -y mysql-server
启动MySQL服务
sudo systemctl start mysqld
设置MySQL开机自启
sudo systemctl enable mysqld
获取临时密码 安装完成后,MySQL会生成一个临时密码。你可以在日志文件中找到它:
sudo grep 'temporary password' /var/log/mysqld.log
运行安全脚本 使用临时密码登录MySQL,并运行安全脚本以设置新密码和其他安全选项:
sudo mysql_secure_installation
按照提示操作,设置新密码,删除匿名用户,禁止root远程登录等。
验证安装 登录MySQL并检查版本:
mysql -u root -p
输入你设置的新密码,然后运行:
SELECT VERSION();
如果你更喜欢PostgreSQL,可以按照以下步骤安装:
添加PostgreSQL仓库
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
安装PostgreSQL
sudo yum install -y postgresql13-server
初始化数据库
sudo postgresql-setup --initdb
启动PostgreSQL服务
sudo systemctl start postgresql
设置PostgreSQL开机自启
sudo systemctl enable postgresql
获取临时密码 临时密码通常会在日志中显示:
sudo grep 'password' /var/log/postgresql/postgresql-13-main.log
切换到postgres用户并修改密码
sudo -u postgres psql
在psql shell中:
ALTER USER postgres WITH PASSWORD 'your_new_password';
验证安装 登录PostgreSQL并检查版本:
psql -U postgres -c "SELECT version();"
MariaDB是MySQL的一个分支,兼容性好且更新频繁:
添加MariaDB仓库
sudo yum install -y https://yum.mariadb.org/MariaDB/mariadb.repo.d/2.7/linux/centos8-amd64/MariaDB.repo
安装MariaDB服务器
sudo yum install -y mariadb-server mariadb
启动MariaDB服务
sudo systemctl start mariadb
设置MariaDB开机自启
sudo systemctl enable mariadb
获取临时密码
sudo grep 'temporary password' /var/log/mariadb/mariadb.log
运行安全脚本
sudo mysql_secure_installation
验证安装 登录MariaDB并检查版本:
mysql -u root -p
输入你设置的新密码,然后运行:
SELECT VERSION();
以上步骤适用于CentOS 8。如果你使用的是CentOS 7或其他版本,可能需要调整仓库地址和包名。记得在安装过程中根据实际情况调整命令。