• python自动化之连接数据库


    # -*- coding: utf-8 -*-

    """

    Created on Fri Mar 20 10:50:56 2015

    @author: sl

    """

    import os

    import MySQLdb

    import pandas as pd

    MySQL_NAME = os.getenv('MySQL_NAME', '*')

    MySQL_USER = os.getenv('MySQL_USER', '*')

    MySQLPASSWORD = os.getenv('MySQL_PASSWORD', '*')

    MySQL_HOST = os.getenv('MySQL_HOST', '*')

    MySQL_PORT = os.getenv('MySQL_PORT','*')

    #MySQL_NAME = os.getenv('MySQL_NAME', 'mysql')

    #MySQL_USER = os.getenv('MySQL_USER', 'root')

    #MySQLPASSWORD = os.getenv('MySQL_PASSWORD', '123456')

    #MySQL_HOST = os.getenv('MySQL_HOST', 'localhost')

    #MySQL_PORT = os.getenv('MySQL_PORT','3306')

    def connect():

        db=MySQLdb.connect(host=MySQL_HOST, user=MySQL_USER, passwd=MySQLPASSWORD, db=MySQL_NAME, charset="utf8")   

        return db

    def sqlSelect(sql,db):

            #include:select

            cr=db.cursor()

            cr.execute(sql)

            rs=cr.fetchall()

            cr.close()

            return rs

  • 相关阅读:
    编译错误总结。
    9.7
    9.5
    9.6
    9.4
    9.3
    FutureTask取结果超时代码小测试
    java concurrent包常用类小结
    java Nio零散知识点整理
    java进阶教程unit_2java常用类(2)
  • 原文地址:https://www.cnblogs.com/dudumiaomiao/p/7241953.html
Copyright © 2020-2023  润新知