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.
Top comments (0)