ubuntu server create database and create new user with password for there database in postgresql.
Pheak Pheasa
Posted on April 3, 2024
To create a new database and a new user with a password in PostgreSQL on Ubuntu Server, you can follow these steps:
- Install PostgreSQL if it's not already installed:
sudo apt update
sudo apt install postgresql postgresql-contrib
- Switch to the
postgres
user:
sudo -i -u postgres
- Access the PostgreSQL prompt:
psql
- Create a new database:
CREATE DATABASE mydatabase;
- Create a new user and set a password:
CREATE USER myuser WITH PASSWORD 'mypassword';
Replace myuser
with your desired username and mypassword
with your desired password.
- Grant privileges on the database to the user:
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
- Exit the PostgreSQL prompt:
\q
- Exit from the
postgres
user:
exit
That's it! You've now created a new database and a new user with a password in PostgreSQL on your Ubuntu Server.
💖 💪 🙅 🚩
Pheak Pheasa
Posted on April 3, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.