【发布时间】:2017-01-03 04:52:15
【问题描述】:
我写了一个 python 脚本来执行我的 sql 脚本。当我使用源手动运行这个 sql 脚本时,它不会给我任何错误,只是警告,它完全执行为:
mysql> source the_actual_script.sql
Database changed
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.29 sec)
Query OK, 0 rows affected (0.00 sec)
mysql>
但是当我尝试通过我的 python 代码运行它时:
import MySQLdb
db = MySQLdb.connect("aws.eu-central-1.rds.amazonaws.com","prod_user","pass","db_name")
cursor = db.cursor()
for line in open("/home/ubuntu/PATCHER/the_check_query.sql"):
print cursor.execute(line)
db.close()
它给了我错误:
test.py:8: Warning: PROCEDURE saas_neopostsa.temp_prod does not exist
cursor.execute(line)
test.py:8: Warning: PROCEDURE saas_neopostsa.temp_prod_neopost does not exist
cursor.execute(line)
test.py:8: Warning: PROCEDURE saas_neopostsa.temp_prod_neopostsa does not exist
cursor.execute(line)
test.py:8: Warning: Unknown table 'temp_identity_neopostsa'
cursor.execute(line)
test.py:8: Warning: Unknown table 'temp_identity'
cursor.execute(line)
Traceback (most recent call last):
File "test.py", line 8, in <module>
cursor.execute(line)
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1065, 'Query was empty')
有人可以帮我解决一下问题吗?
【问题讨论】:
标签: python mysql python-2.7