|
|
|
@ -40,10 +40,14 @@ class MySQLService: |
|
|
|
|
password = gen_password() |
|
|
|
|
search_for_user = f"SELECT user FROM mysql.user WHERE user='{username}'" |
|
|
|
|
search_for_db = f"SHOW DATABASES LIKE '{username}'" |
|
|
|
|
create_user = f"CREATE USER '{username}'@'localhost' IDENTIFIED BY %(password)s" |
|
|
|
|
create_user = f""" |
|
|
|
|
CREATE USER '{username}'@'localhost' IDENTIFIED BY %(password)s; |
|
|
|
|
CREATE USER '{username}'@'%' IDENTIFIED BY %(password)s; |
|
|
|
|
""" |
|
|
|
|
create_database = f""" |
|
|
|
|
CREATE DATABASE {username}; |
|
|
|
|
GRANT ALL PRIVILEGES ON {username}.* TO '{username}'@'localhost'; |
|
|
|
|
GRANT ALL PRIVILEGES ON {username}.* TO '{username}'@'%'; |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
with self.mysql_connection() as con: |
|
|
|
@ -59,7 +63,10 @@ class MySQLService: |
|
|
|
|
def reset_db_passwd(self, username: str) -> str: |
|
|
|
|
password = gen_password() |
|
|
|
|
search_for_user = f"SELECT user FROM mysql.user WHERE user='{username}'" |
|
|
|
|
reset_password = f"ALTER USER '{username}'@'localhost' IDENTIFIED BY %(password)s" |
|
|
|
|
reset_password = f""" |
|
|
|
|
ALTER USER '{username}'@'localhost' IDENTIFIED BY %(password)s |
|
|
|
|
ALTER USER '{username}'@'%' IDENTIFIED BY %(password)s |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
with self.mysql_connection() as con: |
|
|
|
|
with con.cursor() as cursor: |
|
|
|
@ -70,8 +77,11 @@ class MySQLService: |
|
|
|
|
return password |
|
|
|
|
|
|
|
|
|
def delete_db(self, username: str): |
|
|
|
|
drop_user = f"DROP USER IF EXISTS '{username}'@'localhost'" |
|
|
|
|
drop_db = f"DROP DATABASE IF EXISTS {username}" |
|
|
|
|
drop_user = f""" |
|
|
|
|
DROP USER IF EXISTS '{username}'@'localhost'; |
|
|
|
|
DROP USER IF EXISTS '{username}'@'%'; |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
with self.mysql_connection() as con: |
|
|
|
|
with con.cursor() as cursor: |
|
|
|
|