sudo yum update -y
wget
(用于下载仓库文件)、vim
(可选,用于编辑配置文件)。sudo yum install -y wget vim
sudo yum remove mysql mysql-server mariadb mariadb-server -y
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm
57
替换为80
)执行命令:sudo yum install -y mysql-community-server
(系统会自动下载并安装MySQL服务器及依赖包)
sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo systemctl status mysqld
(显示“active (running)”即为成功)sudo grep 'temporary password' /var/log/mysqld.log
mysql -u root -p
(粘贴临时密码,输入时不显示)执行安全脚本:sudo mysql_secure_installation
按提示完成以下操作:
CREATE DATABASE testdb;
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'password123'; GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost'; FLUSH PRIVILEGES;
(若需允许远程访问,将'localhost'
改为'%'
,并执行GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'; FLUSH PRIVILEGES;
)执行命令:sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
(该命令会添加PostgreSQL的官方软件源,支持多版本安装)
执行命令:sudo yum install -y postgresql14-server
(系统会自动安装PostgreSQL服务器及依赖包)
执行命令:sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
(该命令会创建PostgreSQL的数据目录,默认路径为/var/lib/pgsql/14/data
)
sudo systemctl start postgresql-14
sudo systemctl enable postgresql-14
sudo systemctl status postgresql-14
(显示“active (running)”即为成功)su - postgres
psql
pg_hba.conf
文件(允许所有IP访问):vim /var/lib/pgsql/14/data/pg_hba.conf
host all all 0.0.0.0/0 md5
postgresql.conf
文件(开启远程监听):vim /var/lib/pgsql/14/data/postgresql.conf
listen_addresses
行,修改为:listen_addresses = '*'
sudo systemctl restart postgresql-14
sudo useradd kong
su - postgres
psql
CREATE USER kong WITH PASSWORD 'kong'; CREATE DATABASE kong OWNER kong; GRANT ALL PRIVILEGES ON DATABASE kong TO kong;
\q
,再退出linux用户:exit
sudo tail -n 50 /var/log/mysqld.log
,根据错误信息解决(如端口冲突、磁盘空间不足)。chown -R postgres:postgres /var/lib/pgsql/14/data
。postmaster.pid
文件(若存在):sudo rm -f /var/lib/pgsql/14/data/postmaster.pid
,再重启服务。