官术网_书友最值得收藏!

Multiple database connections

In MySQL for Python, all database objects are discrete. All you need do is to connect with each under a different name. Consider the following:

mydb1 = MySQLdb.connect(host="localhost", 
                        user="skipper", 
                        passwd="mysecret", 
                        db="fish")
mydb2 = MySQLdb.connect(host="localhost", 
                        user="skipper", 
                        passwd="mysecret", 
                        db="fruit")
cursor1 = mydb1.cursor()
cursor2 = mydb2.cursor()

The objects then function like any other variable or object. By calling their methods and attributes separately, you can interact with either or even copy from one to the other.

主站蜘蛛池模板: 林周县| 乌审旗| 罗城| 稷山县| 收藏| 牟定县| 长宁县| 霞浦县| 桑日县| 郑州市| 潼关县| 宝鸡市| 固始县| 辛集市| 安塞县| 淮滨县| 中卫市| 梁山县| 卢龙县| 滁州市| 沙坪坝区| 桦川县| 广东省| 革吉县| 法库县| 高青县| 南召县| 东辽县| 信丰县| 大田县| 九龙坡区| 贵州省| 富平县| 红河县| 微博| 家居| 清苑县| 湾仔区| 新源县| 壤塘县| 阳信县|