centos 7 安装postgresql
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL:
sudo yum install -y postgresql14-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
连接数据库(postgres用户连接)
[root@AY1405261748171252caZ ~]# su - postgres Last failed login: Sat Nov 13 11:16:40 CST 2021 from 159.89.12.78 on ssh:notty There were 1238 failed login attempts since the last successful login. -bash-4.2$ -bash-4.2$ psql psql (14.1) Type "help" for help. postgres=# select version(); version --------------------------------------------------------------------------------------------------------- PostgreSQL 14.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit (1 row)
创建root用户,如下:
[root@AY1405261748171252caZ ~]# su - postgres
Last login: Sat Nov 13 14:54:34 CST 2021 on pts/0
-bash-4.2$ psql -U postgres
psql (14.1)
Type "help" for help.
postgres=# create user root with password 'password';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE mydatabase to root;
ERROR:  database "mydatabase" does not exist
postgres=# CREATE DATABASE mydatabase;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE mydatabase to root;
GRANT
postgres=# ALTER ROLE root WITH SUPERUSER;
ALTER ROLE
postgres=# \q
-bash-4.2$ 
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号