'Python MySQL Query not Working when Run in python but works fine in SQL > CREATE USER

class Setup:
    def __init__(self,mydb,User):
        self._mydb = mydb
        self._User = User
    def DataBaseSetup(self):
        mycursor = self._mydb.cursor(buffered=True)
        mycursor.execute("CREATE DATABASE IF NOT EXISTS StaffDB;")
        mycursor.execute("CREATE TABLE IF NOT EXISTS StaffDB.Staff(UserName VarChar(40) PRIMARY KEY,Privlage Int Not Null,FirstName VARCHAR(20),LastName VARCHAR(20),ContactNo VarChar(11),jobTitle VARCHAR(40),startDate DATE,salary INT,DateOfBirth DATE,Address VARCHAR(120))")
        mycursor.execute("CREATE TABLE IF NOT EXISTS StaffDB.Classes (RoomNO INT AUTO_INCREMENT PRIMARY KEY, Teacher int, Department VARCHAR(255), ITAccess boolean, ClassCapacity Int)")
        mycursor.execute("CREATE TABLE IF NOT EXISTS StaffDB.Pupils (PupilID INT AUTO_INCREMENT PRIMARY KEY, RegClass int, FirstName VARCHAR(20), LastName VARCHAR(20), ContactNo VARCHAR(11), Address VARCHAR(120))")
        sql = "INSERT IGNORE INTO StaffDB.Staff (Username,Privlage,FirstName,LastName,ContactNo,jobTitle,startDate,salary,DateOfBirth,Address) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
        val = [
             ("root","0","Fname","LName","07783812342","Admin","2012-12-22","1540000","1997-01-01","Black address")
        ]

        mycursor.executemany(sql, val)
        self._mydb.commit()
        print(mycursor.rowcount, "record was inserted.")
        mycursor.execute("CREATE USER 'Tam'@'localhost' IDENTIFIED BY 'Tam';GRANT ALL ON staffdb.* TO 'Tam'@'localhost';FLUSH PRIVILEGES;",multi=True)
    def GetPriv(self):
      mycursor = self._mydb.cursor(buffered=True)
      mycursor.execute(f"SELECT Privlage FROM StaffDB.Staff WHERE USERNAME LIKE '{self._User}'")
      myresult = mycursor.fetchall()
      Priv = myresult[0]
      return Priv[0]

The Line mycursor.execute("CREATE USER 'Tam'@'localhost' IDENTIFIED BY 'Tam';GRANT ALL ON staffdb.* TO 'Tam'@'localhost';FLUSH PRIVILEGES;",multi=True) is run shows no errors but has no effect on the DataBase. when i run the Same Code from the database it works perfectly fine.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source