mysql Programming error 書き方に気をつけないと出るエラー例2つ
不要な「,」などがあると以下のようなエラーが出ます。
エラーの出たチュートリアル:「データの追加」箇所
データベースによるデータ管理 | 東京大学グローバル消費インテリジェンス寄附講座
ーーーーーーーーーーーターミナル エラー文(1):
Traceback (most recent call last):
File "testmysql.py", line 48, in <module>
dbcur.execute('''INSERT INTO testtweets2 (tweet_id, ccontent, user_id), VALUES(%s, %s, %s)''', (data,))
File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 494, in execute
psub = _ParamSubstitutor(self._process_params(params))
File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 379, in _process_params
"Failed processing format-parameters; %s" % err)
mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'tuple' cannot be converted to a MySQL type
ーーーーーーーーーーーターミナル エラー文(2):
Traceback (most recent call last):
File "testmysql.py", line 48, in <module>
dbcur.execute('''INSERT INTO testtweets2 (tweet_id, ccontent, user_id), VALUES(%s, %s, %s)''', (data))
File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 507, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 722, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 640, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' VALUES(138297393, '^_^', 38979)' at line 1
ーーーーーーーーーーーーーーーーーーpythonファイル (一部)
注意:「,」は不要だった。
dataset =[
(138297393, '^_^', 38979),
(298379847, '(- - ;)', 38979),
(928398329, '*1
#実際にMySQLに反映させる dbcon.commit()