Forums

MySQL Error - mysql_exceptions.OperationalError

Hello, Am running on the free plan, I have this script below that insert into MySQl database. It works fine on the local machine, but same script shows error when deployed on PythonAnyWhere.

What could be wrong with my script? Or is this operation requiring an upgrade?

The script uses MySQLdb module as seen below...

import MySQLdb conn=MySQLdb.connect( host='username.mysql.pythonanywhere-services.com', user='username', passwd='password', db='username$pydb')

cur = conn.cursor()

sql1 = "INSERT INTO pydb.mytable (check_in_timestamp, check_out_timestamp, club_id, id, member_id, status, status_message) VALUES ('233333', '3454554', '434434', '232', '4554', 'reetrttrtr', 'rtttttttttrt')"; cur.execute(sql1) conn.commit()

sql = 'SELECT * from mytable'; countrow = cur.execute(sql)

print (countrow)

conn.close()

Error is as below....

Traceback (most recent call last): File "/home/shintaku/VirtuaGym/VirtuaGym_Script.py", line 45, in <module> cur.execute(sql1) File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py", line 250, in execute self.errorhandler(self, exc, value) File "/usr/local/lib/python3.6/dist-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler raise errorvalue File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py", line 247, in execute res = self._query(query) File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py", line 411, in _query rowcount = self._do_query(q) File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py", line 374, in _do_query db.query(q) File "/usr/local/lib/python3.6/dist-packages/MySQLdb/connections.py", line 292, in query _mysql.connection.query(self, query) _mysql_exceptions.OperationalError: (1142, "INSERT command denied to user 'shintaku'@'10.0.0.221' for table 'mytable'")

I think the table name should be something like shintaku$mytable instead of mytable

Yeah, that came close. I had to change the db name close to mytable in the script, to start with username as suggested.... and it works!

Anywhere reference to database is made, it has to be in the form: username$database_name

Yes, that's right. The full name of your database includes your username (truncated to 16 characters), then a dollar sign, then the name you originally specified.