在CentOS系统上安装数据库软件,可以按照以下步骤进行。这里以MySQL为例,介绍如何在CentOS 7和CentOS 8上安装MySQL数据库。
更新系统包
sudo yum update -y
安装MySQL服务器
sudo yum install mysql-server -y
启动MySQL服务
sudo systemctl start mysqld
设置MySQL开机自启动
sudo systemctl enable mysqld
获取临时密码 安装完成后,MySQL会生成一个临时密码,你可以在日志文件中找到它。
sudo grep 'temporary password' /var/log/mysqld.log
运行安全脚本 使用临时密码登录MySQL,并运行安全脚本以设置新密码和其他安全选项。
sudo mysql_secure_installation
登录MySQL 使用新密码登录MySQL。
mysql -u root -p
更新系统包
sudo dnf update -y
安装MySQL服务器
sudo dnf install mariadb-server -y
启动MariaDB服务
sudo systemctl start mariadb
设置MariaDB开机自启动
sudo systemctl enable mariadb
获取临时密码 安装完成后,MariaDB会生成一个临时密码,你可以在日志文件中找到它。
sudo grep 'temporary password' /var/log/mariadb/mariadb.log
运行安全脚本 使用临时密码登录MariaDB,并运行安全脚本以设置新密码和其他安全选项。
sudo mysql_secure_installation
登录MariaDB 使用新密码登录MariaDB。
mysql -u root -p
如果你需要安装其他数据库软件,如PostgreSQL、MongoDB等,可以使用以下命令:
安装PostgreSQL
sudo yum install postgresql-server postgresql-contrib -y
启动PostgreSQL服务
sudo systemctl start postgresql
设置PostgreSQL开机自启动
sudo systemctl enable postgresql
运行安全脚本
sudo postgresql-setup --initdb
登录PostgreSQL
sudo -u postgres psql
导入MongoDB仓库
sudo cat <<EOF > /etc/yum.repos.d/mongodb-org.repo
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
EOF
安装MongoDB
sudo yum install -y mongodb-org
启动MongoDB服务
sudo systemctl start mongod
设置MongoDB开机自启动
sudo systemctl enable mongod
登录MongoDB
mongo
通过以上步骤,你可以在CentOS系统上成功安装并配置数据库软件。