Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将数据插入到我的数据库中,但使用以下代码出现 MYSQL 语法错误:
import MySQLdb db=MySQLdb.connect(host="localhost",user="root",passwd="",db="database") cursor = db.cursor() sql = "INSERT INTO table1('col1','col2') values ('val1','val2');" cursor.execute(sql) db.commit()
列名周围没有引号。
INSERT INTO table1(col1, col2) VALUES ('val1', 'val2');
您可以在列名周围使用反引号,但不能使用单引号。