zoukankan      html  css  js  c++  java
  • Postgresql配置

    YUM安装:

    ------------------------------------------------------------------------------------------

    1、安装Postgresql安装源:

    # yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    # yum clean all
    # yum makecache
    

    2、安装数据库:

    # yum install postgresql12 postgresql12-server
    

    3、始化数据库:

    # service postgresql-12 initdb
    

    4、启动数据库服务:

    # service postgresql-12 start
    # chkconfig postgresql-12 on
    

    5、登录数据库:

    # su postgres
    $ psql
    

    6、修改管理员账号密码:

    =# alter user postgres with encrypted password 'mypass';
    

    7、退出数据库:

    =# q 或者 quit
    

    源码编译安装:

    ------------------------------------------------------------------------------------------

    1、官网下载Postgresql:

    # wget https://ftp.postgresql.org/pub/source/v12.3/postgresql-12.3.tar.gz
    

    2、安装依赖包:

    # yum -y install bison flex readline-devel zlib-devel
    

    3、解压源码包:

    # tar -xzvf postgresql-12.3.tar.gz
    

    4、编译源码包:

    # ./configure --prefix=/usr/local/postgresql
    # make
    # make install
    

    5、增加postgres账户:

    # groupadd postgres
    # useradd -g postgres postgres
    

    6、新增DATA目录:

    # mkdir /usr/local/postgresql/data
    # chown -R postgres.postgres /usr/local/postgresql
    

    7、数据库系统初始化:

    $ /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/
    

    8、增加环境变量:

    $ vim /home/postgres/.bash_profile
    export PGHOME=/usr/local/postgresql
    export PGDATA=/usr/local/postgresql/data
    export PATH=$PATH:$HOME/bin:$PGHOME/bin
    
    $ source /home/postgres/.bash_profile
    

    9、启动数据库服务:

    $ /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ -l logfile start
    $ /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ stop
    $ /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ -m fast restart
    

    10、添加开机启动项目:

    $ /usr/local/src/postgresql-12.3/contrib/start-scripts/linux /etc/init.d/postgresql
    $ chmod a+x /etc/init.d/postgresql
    
    $ vim /etc/init.d/postgresql
    按实际情况修改如下项目:
    # Installation prefix
    prefix=/usr/local/postgresql
    # Data directory
    PGDATA="/usr/local/postgresql/data"
    

    添加开机项目:

    $ chkconfig --add postgresql
    

    11、设置管理员用户密码:

    $ psql -U postgres
    =# ALTER USER postgres with encrypted password '17track';
    =# quit
    

    常用命令:

    --------------------------------------------------------------------------

    查看所有数据库:

    =# l 或者 list
    

    列出当前数据库的表:

    =# d
    

    创建数据库:

    =# create database mydb;
    

    切换数据库:

    =# c mydb
    

    在当前数据库插入表:

    =# create table test(id int,body varchar(100));
    

    新建用户:

    =# create user test with password 'test';
    

    修改账号密码:

    =# alter user postgres with encrypted password 'mypass';
    

    赋予指定账号到指定数据库权限:

    =# grant all privileges on database mydb to test;
    

    移除指定账号到指定数据库权限:

    =# revoke all privileges on database mydb to test;
    

    [THE END]

  • 相关阅读:
    信步漫谈之Struts2—输入校验(编码方式)
    信步拾遗之Java反射机制浅析
    信步漫谈之Log4j—基础介绍
    Log4J基础详解及示例大全(转)
    设计模式之Bridge(桥接)(转)
    设计模式之Adapter(适配器)(转)
    设计模式之Facade(外观)(转)
    设计模式之Factory(工厂)(转)
    设计模式之Flyweight(享元)(转)
    基于CentOS7系统部署cobbler批量安装系统
  • 原文地址:https://www.cnblogs.com/configure/p/13398662.html
Copyright © 2011-2022 走看看