404 Not Found-浪潮云官网
  

 

免费注册

很抱歉,您要找的信息不存在

浪潮云赋能智慧未来,为用户提供安全可信,个性定制的云计算服务,助企业无忧上云!

返回首页> 云市场> 服务社区>

帮助文档(华北一、二)

  • 1. DW客户端的方式访问

    ● 1.1 DW(greenplum)客户端方式访问(以Centos为例)

    如果你选择的数据仓库类型是greenplum、可以采用下面的方式访问

    1)下载greenplum客户端解压

     wget http://downloadupt.infile.inspurcloud.cn/greenplum-client.tar.gz

    tar -zxvf greenplum-client.tar.gz

    2)配置dw客户端

    进入greenplum-client安装目录,编辑 greenplumclientpath.sh 修改UDWHOME:export UDWHOME= client安装目录(如/root/greenplum-client)

    3) 使配置生效

    在~/.bashrc中添加如下配置

    source /data/greenplum-client/greenplumclientpath.sh

    source ~/.bashrc

    备注:/data/greenplum-client是greenplum-client的安装路径

    4) 连接数据库

    psql -h hostIP(或域名) –U username -d database -p port –W

    ● 1.2 udw(udpg)客户端方式访问(以Centos为例)

    如果你选择的数据仓库类型是udpg、可以采用下面的方式访问

    1)下载dw客户端

     wget http://udwclient.ufile.ucloud.cn/udw-client.tar

    解压: tar xvf udw-client.tar

    2)配置udw客户端

    进入udw-client安装目录,编辑 udwclientpath.sh,修改UDWCLIENT:export UDWCLIENT= client安装目录(如/root/udw-client)

    3)使配置生效在~/.bashrc中添加如下配置

     
    source /data/udw-client/udw_client_path.sh 
    source ~/.bashrc 
    备注:/data/udw-client是udw-client的安装路径

    4) 连接数据库

    psql -h hostIP(或域名) –U username -d database -p port –W

    2. python客户端访问

     $yum install python-psycopg2

    ● 示例1. 连接DW testconn.py

     
    #!/usr/bin/python   
    import psycopg2 
    conn = psycopg2.connect(database="dev", user="username", 
    password="password", host="hostIP", port="port") 
    print "Opened database successfully"

    执行 python testconn.py

    ● 示例2. 创建一个表 createTable.py

     
    #!/usr/bin/python   
    import psycopg2 
    conn = psycopg2.connect(database="dev", user="username", 
    password="password", host="hostIP", port="port") 
    print "Opened database successfully" 
    cur = conn.cursor() 
    cur.execute('''CREATE TABLE COMPANY     
    (ID INT PRIMARY KEY     NOT NULL,     
    NAME           TEXT    NOT NULL,     
    AGE            INT     NOT NULL,     
    ADDRESS        CHAR(50),     
    SALARY         REAL);''') 
    print "Table created successfully" 
    conn.commit() 
    conn.close()

    ● 示例3. 插入记录 insert.py

     
    #!/usr/bin/python   
    import psycopg2 
    conn = psycopg2.connect(database="dev", user="username", 
    password="password", host="hostIP", port="port") 
    print "Opened database successfully" 
    cur = conn.cursor() 
    cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \   
    VALUES (1, 'Paul', 32, 'California', 20000.00 )"); 
    cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \   
    VALUES (2, 'Allen', 25, 'Texas', 15000.00 )"); 
    conn.commit() 
    print "Records created successfully"; 
    conn.close()

    ● 示例4. 查询 select.py

     
    #!/usr/bin/python   
    import psycopg2 conn = psycopg2.connect(database="dev", user="username", 
    password="password", host="hostIP", port="port") 
    print "Opened database successfully" 
    cur = conn.cursor() 
    cur.execute("SELECT id, name, address, salary  from COMPANY") 
    rows = cur.fetchall() 
    for row in rows:     
      print "ID = ", row[0]     
      print "NAME = ", row[1]     
      print "ADDRESS = ", row[2]     
      print "SALARY = ", row[3], "\n" 
    print "Operation done successfully"; 
    conn.close() 

    ● 示例5. 更新 update.py

     
    #!/usr/bin/python   
    import psycopg2 
    conn = psycopg2.connect(database="dev", user="username", 
    password="password", host="hostIP", port="port") 
    print "Opened database successfully" 
    cur = conn.cursor() 
    cur.execute("UPDATE COMPANY set SALARY = 25000.00 where ID=1") 
    conn.commit 
    print "Total number of rows updated :", cur.rowcount 
    cur.execute("SELECT id, name, address, salary  from COMPANY") 
    rows = cur.fetchall() 
    for row in rows:    
      print "ID = ", row[0]    
      print "NAME = ", row[1]    
      print "ADDRESS = ", row[2]    
      print "SALARY = ", row[3], "\n" 
    print "Operation done successfully"; 
    conn.close() 

    ● 示例6. 删除 delete.py

     
    #!/usr/bin/python   
    import psycopg2 conn = psycopg2.connect(database="dev", user="username",