Приветствую!
connection = MySQLdb.connect(host='localhost', user=db_user, passwd=db_password)
cursor = connection.cursor()
cursor.execute("USE mysql;")
sql = "SELECT * FROM db WHERE Db='%s';" % database.replace("_", "\_")
print sql
cursor.execute(sql)
SELECT * FROM db WHERE Db='test\_db';
... <опущено>
TypeError: 'str' object is not callable
Аналогичную ошибку выдает:
cursor.execute("SELECT * FROM db WHERE Db=%s;", (database.replace("_", "\_"),))
MySQL:
mysql> SELECT User,Db FROM db WHERE Db = 'test\_db';
+-------------+------------+
| User | Db |
+-------------+------------+
| test | test\_db |
| test_user | test\_db |
+-------------+------------+
2 rows in set (0.00 sec)