This commit is contained in:
2026-11-03 22:04:11 +08:00
parent 56ab927f8c
commit b9e6469635
3 changed files with 16 additions and 44 deletions

View File

@@ -1469,8 +1469,7 @@ def addDb():
return mw.returnJson(False, '数据库已存在!')
try:
result = pdb.execute("create database `" + dbname +
"` DEFAULT CHARACTER SET " + codeing + " COLLATE " + codeStr)
result = pdb.execute("create database `" + dbname +"` DEFAULT CHARACTER SET " + codeing + " COLLATE " + codeStr)
except Exception as e:
result = e
# print result
@@ -1478,14 +1477,10 @@ def addDb():
if isError != None:
return isError
# 清理同名残留用户,失败忽略(兼容DROP USER不支持IF EXISTS的旧版本)
try:
pdb.execute("drop user '" + dbuser + "'@'localhost'")
except Exception:
pass
for a in address.split(','):
db_users_access = getDbUserAccess(dbuser)
for user_access in db_users_access:
try:
pdb.execute("drop user '" + dbuser + "'@'" + a + "'")
pdb.execute("drop user `%s`@'%s'" % (db_user, user_access))
except Exception:
pass
@@ -1518,18 +1513,10 @@ def delDb():
except Exception:
pass
try:
users = pdb.query("select Host from user where User='" +
username + "' AND Host!='localhost'")
except Exception:
users = []
try:
pdb.execute("drop user '" + username + "'@'localhost'")
except Exception:
pass
for us in users:
db_users_access = getDbUserAccess(username)
for user_access in db_users_access:
try:
pdb.execute("drop user '" + username + "'@'" + us["Host"] + "'")
pdb.execute("drop user '" + username + "'@'%s'" % (user_access,))
except Exception:
pass
pdb.execute("flush privileges")

View File

@@ -1644,14 +1644,10 @@ def addDb():
if isError != None:
return isError
# 清理同名残留用户,失败忽略(兼容DROP USER不支持IF EXISTS的旧版本)
try:
pdb.execute("drop user '" + dbuser + "'@'localhost'")
except Exception:
pass
for a in address.split(','):
db_users_access = getDbUserAccess(dbuser)
for user_access in db_users_access:
try:
pdb.execute("drop user '" + dbuser + "'@'" + a + "'")
pdb.execute("drop user `%s`@'%s'" % (db_user, user_access))
except Exception:
pass
@@ -1684,18 +1680,10 @@ def delDb():
except Exception:
pass
try:
users = pdb.query("select Host from mysql.user where User='" +
username + "' AND Host!='localhost'")
except Exception:
users = []
try:
pdb.execute("drop user '" + username + "'@'localhost'")
except Exception:
pass
for us in users:
db_users_access = getDbUserAccess(username)
for user_access in db_users_access:
try:
pdb.execute("drop user '" + username + "'@'" + us["Host"] + "'")
pdb.execute("drop user '" + username + "'@'%s'" % (user_access,))
except Exception:
pass
pdb.execute("flush privileges")

View File

@@ -1856,7 +1856,7 @@ def addDb():
db_users_access = getDbUserAccess(dbuser)
for user_access in db_users_access:
try:
pdb.execute("drop user '" + dbuser + "'@'%s'" % (user_access,))
pdb.execute("drop user `%s`@'%s'" % (db_user, user_access))
except Exception:
pass
@@ -2107,17 +2107,14 @@ def setDbRw(version=''):
psdb = pSqliteDb('databases')
dbname = psdb.where("id=?", (uid,)).getField('name')
try:
users = pdb.query(
"select Host from mysql.user where User='" + username + "'")
users = pdb.query("select Host from mysql.user where User='" + username + "'")
except Exception as e:
return mw.returnJson(-1, str(e))
# show grants for demo@"127.0.0.1";
for x in users:
# REVOKE ALL PRIVILEGES ON `imail`.* FROM 'imail'@'127.0.0.1';
sql = "REVOKE ALL PRIVILEGES ON `" + dbname + \
"`.* FROM '" + username + "'@'" + x["Host"] + "';"
sql = "REVOKE ALL PRIVILEGES ON `" + dbname + "`.* FROM '" + username + "'@'" + x["Host"] + "';"
try:
pdb.query(sql)
except Exception: