1

I have script in python where I use MySQLdb connector, but on server MySQLdb isn't installed, so I need change connector. I have example class:

class Foo:

    def __init__(self, config):
        self.logger = logging.getLogger("Foo")
        self.db = MySQLdb.connect(host=config["host"],user=config["user"], passwd=config["passwd"], db=config["db"])

    def get_something(self):
        cursor=self.db.cursor()
        cursor.execute("Select ...")
        for row in cursor:
            self.logger.debug(row)
            yield(row)

f = Foo(config)
f.get_something()

When I use MySQLdb connector it works. In this case python reads all records and store in memory. But when I change connector to mysql.connector script prints some records and raise error:

mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query

This is modified class:

class Foo:

    def __init__(self, config):
        self.logger = logging.getLogger("Foo")
        self.db = mysql.connector.connect(host=config["host"],user=config["user"], passwd=config["passwd"], db=config["db"])

    def get_something(self):
        cursor=self.db.cursor()
        cursor.execute("Select ...")
        for row in cursor:
            self.logger.debug(row)
            yield(row)

f = Foo(config)
f.get_something()

I try run query:

self.db.cursor().execute("SET GLOBAL max_allowed_packet=1073741824")

But I have error:

mysql.connector.errors.ProgrammingError: 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s) for this operation

Is it possible to repair this error? I haven't root access to change privileges and I haven't access to install MySQLdb on server.

krynio
  • 2,442
  • 26
  • 30

2 Answers2

1

you don't need to include global parameter.

cursor = self.db.cursor()
cursor.execute("SET max_allowed_packet=1073741824")

until you close the cursor, the max allowed packet system variable will be the value you assign.

tuku
  • 415
  • 5
  • 12
0

The user that you are using for the application doesn't have this permission, either connect to the server via root and log into mysql and run this command...or give all the permissions to the user (not recommended for application level database users) using

grant all on database.* to user@'%';
flush privileges
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
  • I haven't root access to this server.It is problem. – krynio Dec 15 '14 at 14:25
  • @krynio..This is something related to database permission and your user doesn't have this permission..you even might need to restart the database service too after executing the command SET GLOBAL max_allowed_packet=1073741824 on your database. – Danyal Sandeelo Dec 15 '14 at 14:30
  • My problem isn't connected with permissions. My main problem is that mysql lost connection when I execute query. I try change max_allowed_packet size (i found it in this question http://stackoverflow.com/questions/1884859/lost-connection-to-mysql-server-during-query) but I haven't permission to it. – krynio Dec 15 '14 at 14:53