Skip to content

Instantly share code, notes, and snippets.

@llccing
Created April 18, 2024 02:53
Show Gist options
  • Save llccing/95f2c1246796c90f9c731a94f1bba975 to your computer and use it in GitHub Desktop.
Save llccing/95f2c1246796c90f9c731a94f1bba975 to your computer and use it in GitHub Desktop.
#!/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