Oct-06-2022, 01:57 PM
Hi,
Im connecting to a DB in AWS and want to check if a certain username is on the server
cursor.fecthall () copies the usernames and stores them as a tuple
Is there a way I can search for the username in the Tuple
user in userNames prints out the username 'support' but Im not sure the best way to then search for them
Ive tried a couple of options but none work for me. Being new to Python I thought Id ask on here
If I could search the tuple for a user called 'support' can anyone tell me how its done?
Im assuming fectchall () returns a Tuple although some docs say its a list
I get this returned
('mysql.infoschema', 'localhost')
('mysql.session', 'localhost')
('mysql.sys', 'localhost')
('admin', 'localhost')
('support', 'localhost')
Ive tried
Im connecting to a DB in AWS and want to check if a certain username is on the server
cursor.fecthall () copies the usernames and stores them as a tuple
Is there a way I can search for the username in the Tuple
user in userNames prints out the username 'support' but Im not sure the best way to then search for them
Ive tried a couple of options but none work for me. Being new to Python I thought Id ask on here
If I could search the tuple for a user called 'support' can anyone tell me how its done?
Im assuming fectchall () returns a Tuple although some docs say its a list
I get this returned
('mysql.infoschema', 'localhost')
('mysql.session', 'localhost')
('mysql.sys', 'localhost')
('admin', 'localhost')
('support', 'localhost')
Ive tried
for userName in users: if 'support' in users: print('name is there') else: print('user isnt here')However that just returns the else statement even though the user is there
connection = pymysql.connect( host=db_secrets['host'], user=db_secrets['username'], password=db_secrets['password'], database=db_secrets['dbname'] ) cursor = connection.cursor() logger.info("SUCCESS: Connection to RDS MySQL instance succeeded") sql_GetUser = "select user, host from mysql.user;" cursor.execute(sql_GetUser) logger.info("Got a list of users") users= cursor.fetchall () print("User List:") for userName in users: print(userName) connection.close() print("The connection is closed") cursor.close() logger.info("Successfully closed the cursor")