db= pymysql.connect(host="localhost",user="lhx",password="Ly123456")
cursor=db.cursor() # 使用cursor()方法獲取操作游標
print('創建帳號開始啦!')
sql="create user '%s'@'%s' identified by '%s'"%(self.username.get(),'%',self.password.get())
print('111')
cursor.execute(sql) # 創建可在所有機器上可連接的用戶密碼
print('帳號創建成功!')
sql="grant all privileges on *.* to '%s'@'%s'"%(self.username.get(),'%')
print(sql)
print('222')
cursor.execute(sql) # 給上面創建的用戶名、密碼分配權限
print('權限分配成功!')
db.close()
這段代碼 上面的帳號、密碼是可以創建成功的,但下面的代碼,給這個帳號分配權限卻不行。但是我把print(sql)中顯示在運行視窗中的字串復制粘貼到mysql命令列中執行是可以的,說明陳述句是沒問題,但在python中就無法執行,出現如下錯誤:
pymysql.err.OperationalError: (1045, "Access denied for user 'lhx'@'%' (using password: YES)")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/268825.html
上一篇:尋求Python大佬
下一篇:關于獲取京東商品評價數的問題
