From d74eeffda043a5295725e7380c5b5bdd19cc51b7 Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Fri, 3 Sep 2021 20:38:58 -0400 Subject: [PATCH] allow mysql connections from unix socket --- ceod/db/MySQLService.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ceod/db/MySQLService.py b/ceod/db/MySQLService.py index 043a906..917c483 100644 --- a/ceod/db/MySQLService.py +++ b/ceod/db/MySQLService.py @@ -47,10 +47,12 @@ class MySQLService: 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 '{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}'@'%'; """ @@ -67,7 +69,8 @@ class MySQLService: password = gen_password() search_for_user = f"SELECT user FROM mysql.user WHERE user='{username}'" reset_password = f""" - ALTER USER '{username}'@'%' IDENTIFIED BY %(password)s + ALTER USER '{username}'@'localhost' IDENTIFIED BY %(password)s; + ALTER USER '{username}'@'%' IDENTIFIED BY %(password)s; """ with self.mysql_connection() as con, con.cursor() as cursor: @@ -80,9 +83,11 @@ class MySQLService: def delete_db(self, username: str): 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, con.cursor() as cursor: cursor.execute(drop_db) cursor.execute(drop_user) +