0

i have a MySQL query like this

cursor.execute("GRANT USAGE ON %s.* TO %s@%s", [db, user, host])

Python generate a query like

GRANT USAGE ON 'db'.* TO 'user'@'host';

But the apostrophes around 'db' are not allowed in MySQL. Any ideas?

1 Answer 1

1

A simple way to get around this.

grant = "GRANT USAGE ON %s.* TO '%s'@'%s'" % [db, user, host]
cursor.execute(grant)

HTH

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Are the arguments safe for mysql injections with this method?
It's not bullet proof - but these are typically not coming from an end user generated data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.