python的MySQLdb包rollback對create語句無效嗎?
問題描述
業(yè)務(wù)需要用腳本自動創(chuàng)建數(shù)據(jù)庫表,并注冊到一個(gè)注冊表中。環(huán)境是python2.7+mysql5.6+MySQLdb代碼如下,其中createSchemaCmd是create schemasql指令,createTableCmd是create table指令,registerTableCmd是insert table指令
dbConn = DBOHelper.getConnect(DB_HOST, DB_Account, DB_PSW)cur = dbConn.cursor()try: for cmd in [createSchemaCmd, createTableCmd, registerTableCmd]:rst = cur.execute(cmd)dbConn.commit()except MySQLdb.MySQLError, sql_err: dbConn.rollback() print 'Mysql Error %d: %s' % (sql_err.args[0], sql_err.args[1]) raise sql_errfinally: cur.close() dbConn.close()
出現(xiàn)異常時(shí),rollback沒有回滾2個(gè)create相關(guān)的指令。現(xiàn)在我需要rollback建庫和建表指令應(yīng)該怎么做?
問題解答
回答1:DDL VS DML
基本概念
DML 才能 rollback
回答2:直接drop
相關(guān)文章:
1. docker不顯示端口映射呢?2. angular.js - 關(guān)于$apply()3. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””4. macos - mac下docker如何設(shè)置代理5. MySQL數(shù)據(jù)庫中文亂碼的原因6. docker - 各位電腦上有多少個(gè)容器啊?容器一多,自己都搞混了,咋辦呢?7. docker gitlab 如何git clone?8. mysql - 新浪微博中的關(guān)注功能是如何設(shè)計(jì)表結(jié)構(gòu)的?9. css - C#與java開發(fā)Windows程序哪個(gè)好?10. docker-compose 為何找不到配置文件?
