Created
April 18, 2024 02:53
-
-
Save llccing/95f2c1246796c90f9c731a94f1bba975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 定义数据库相关变量 | |
DB_USER="newxxx" | |
DB_PASSWORD="newxxx" | |
DB_NAME="newxxx" | |
# 确保 PostgreSQL 服务正在运行 | |
sudo systemctl start postgresql | |
# 使用 postgres 用户执行 PSQL 命令 | |
sudo -u postgres psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWORD';" | |
sudo -u postgres psql -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;" | |
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;" | |
# 输出连接字符串 | |
echo "Database connection string:" | |
echo "postgresql://$DB_USER:$DB_PASSWORD@localhost:5432/$DB_NAME" | |
echo "Database and user created successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment