Oct-10-2022, 03:33 PM
Hello,
So Im trying to use python to locate a user in SQL and remove it. There will be more than one user that has a username beginning with ROadmin
For example ROadmin1, ROadmin2 and ROadmin3
Currently I can fetch all users and then us this to search for anything beginning with RO
To prevent SQL injection (hacking) the placeholder %s to escape values in the delete statement is used like this
My question is how can my list contain a string that caters for something (like a wildcard) that can point to any used named ROadmin ?
I cant have a list containing the full name to DROP as to DROP a user I need to use a SQL statement of DROP USER 'ROadmin1'@'localhost'
As you can see this contains a list of letters, numbers and a sysmbol.
I need the list, if possible to contain something like a wildcard of 'ROadmin.*'
Is that possible? I tried that but it didnt work
Thanks
So Im trying to use python to locate a user in SQL and remove it. There will be more than one user that has a username beginning with ROadmin
For example ROadmin1, ROadmin2 and ROadmin3
Currently I can fetch all users and then us this to search for anything beginning with RO
if re.search('ROadmin.+', user): print(f" Read Only user {user} found.")Now to remove the users I need to use the DROP statement thats used in SQL.
To prevent SQL injection (hacking) the placeholder %s to escape values in the delete statement is used like this
sql_GetUser = "DROP USER %s;"%userName;]I then have userName as a list.
My question is how can my list contain a string that caters for something (like a wildcard) that can point to any used named ROadmin ?
I cant have a list containing the full name to DROP as to DROP a user I need to use a SQL statement of DROP USER 'ROadmin1'@'localhost'
As you can see this contains a list of letters, numbers and a sysmbol.
I need the list, if possible to contain something like a wildcard of 'ROadmin.*'
Is that possible? I tried that but it didnt work
Thanks
