I am a newbie to Python and trying to figure out how to pass a variable to python for connecting and running mysql commands in Linux. For example:
import mysql.connector
dbconn = mysql.connector.connect(user=‘dbser’, password=‘dbpass’, host=‘127.0.0.1’, database=‘employees’)
If I place the actual database name in the code it works just fine. However, I have not been able to set database to a variable and then pass the variable to the script. I cannot figure out how to get to recognize variables. for example:
dbname = employees
dbconn = mysql.connector.connect(user=‘dbser’, password=‘dbpass’, host=‘127.0.0.1’, database=dbname)
I cannot figure out how to get this to work. Any ideas?