美文网首页
Python操作Oracle数据库

Python操作Oracle数据库

作者: hiningmeng | 来源:发表于2019-03-06 11:12 被阅读0次

    Docker安装Oracle

    因为版权问题,DockerHub上面的Oracle镜像很多都没有安装的,需要手动下载安装包,启动镜像然后安装。在网上找了很久,找到一个helowin打包好的镜像,安装步骤如下:

    首先在docker环境下载镜像
    docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
    
    启动容器
    docker run -d --name oracle11g -p 1521:1521  -v /opt/data/oracle:/home/oracle/app/oracle/oradata/  registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
    #/home/oracle/app/oracle/oradata/为容器数据文件位置
    
    创建账号
    docker exec -it oracle11g   /bin/bash
    
    #docker里面操作
    sqlplus / as sysdba
    #oracle连接成功后
    create user hixuxu identified by hixuxu ;
    grant dba to hixuxu;
    

    使用cx_Oracle操作Oracle数据库

    环境:

    系统:macOS Mojave

    Python:Python 2.7.10

    模块安装
    pip install cx_oracle
    
    macOS安装连接
    unzip instantclient-basic-macos.x64-11.2.0.4.0.zip
    mkdir ~/lib
    cp ./instantclient_11_2/{libclntsh.dylib.11.1,libnnz11.dylib,libociei.dylib} ~/lib/
    
    Oracle的连接
    import cx_Oracle
    db = cx_Oracle.connect('hixuxu/hixuxu@127.0.0.1/helowin')
    print db.version
    db.close()
    

    相关文章

      网友评论

          本文标题:Python操作Oracle数据库

          本文链接:https://www.haomeiwen.com/subject/tqctpqtx.html