Forums

MySQL Script Now Not Working

Has something changed with the mysql databases? The following script, WAS working, but now isn't?

import MySQLdb

db = MySQLdb.connect("xx.mysql.pythonanywhere-services.com","xx", "xx", "xx$xx")

cursor = db.cursor()

cursor.execute("DROP TABLE IF EXISTS group")

# Create table as per requirement
sql = """CREATE TABLE group (
         id MEDIUMINT NOT NULL AUTO_INCREMENT,
         profile_id int,
         keyword VARCHAR(512),
         landing_page VARCHAR(512),
         PRIMARY KEY (id))"""
cursor.execute(sql)
db.commit()
db.close()

error

12:10 ~/ontail/db_scripts$ python group.py 
Traceback (most recent call last):
  File "group.py", line 8, in <module>
    cursor.execute("DROP TABLE IF EXISTS group")
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versi
on for the right syntax to use near 'group' at line 1")

Your error looks like that

DROP TABLE IF EXISTS group

is an incorrect syntax of MySQL.

I was wondering, would

DROP TABLE IF EXISTS group;

work? (The extra semicolon at the end)

Hey,

No, that's not fixed it, all my other scripts are missing it also and were working fine, I don't get it :/

Hi graingerkid,

Last time there was a version chg was probably 6 months ago. Here's one thought. is group a reserved keyword? Did you say maybe have group in quotes to escape it or something previously?

Alternatively, maybe check your database to see if that table exists/maybe that table is in a weird state?

@graingerkid -- just to check, is this problem happening in a new account? Like Conrad says, it's been six months since our last MySQL upgrade. But at that time we set things up so that all old accounts would go from MySQL 5.4 to 5.5, but new accounts would get 5.6.

So if you've got SQL code that you used to run in an old account (using 5.5) but are now trying to run it in an account created in the last 6 months (which would get 5.6) then that might explain the difference.