import MySQLdb
x=raw_input('user> ')
y=raw_input('passwd> ')
db=MySQLdb.Connect(host="localhost", user="%s", passwd="%s" % x,y)
cursor=db.cursor()
cursor.execute('GRANT ALL ON squidctrl.* TO sams@localhost IDENTIFIED BY "connect";')
cursor.execute('GRANT ALL ON squidlog.* TO sams@localhost IDENTIFIED BY "connect";')
cursor.close()
question how can i use it right, i don’t want to enter username and password in script in beginning, i want to it by myself as i wish. when i try it run i put username and pass, after that mistake
Traceback (most recent call last):
File "test.py", line 8, in <module>
db=MySQLdb.Connect('host="localhost", user="%s", passwd="%s"' % x,y)
TypeError: not enough arguments for format string
You don’t need to use string interpolation (
"%s" % ...) here.