pythonからmysqlにinsertするとエラーが出てしまうので対処法を教えていただきたいです。
python 2.7.5 mysql-connector 2.0.4
【テーブル】
テーブル名:pyTest
カラム:name
(中身は空テーブルです)
【code】
[vagrant@localhost pl]$ python IntoSql.py
File "IntoSql.py", line 12
#!/usr/bin/env python
-- coding: utf-8 --
import mysql.connector
if name == 'main':
# データベースに接続
connect = mysql.connector.connect(user='root', host='localhost', database='test', charset='utf8')
cursor = connect.cursor(buffered=True)
# select cursor.execute('insert into pyTest (name) values ('aaa')') #データベースから切断 cursor.close() connect.close()
【出力エラー】
File "IntoSql.py", line 12
cursor.execute('insert into pyTest (name) values ('aaa')')
^
SyntaxError: invalid syntax
初歩的な質問かと思いますが、よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/07/23 15:02