I have two virtual machines. One is used as Agent, One is used as Master. A Mysql Server is installed on Master(Mysql Client is forbidden to be installed on Master which means I can't use mysql command line on Master). The Mysql server has a default user 'root'. Now I want to write a python script which use 'MySQLdb' module on Agent. The test code is easy. just see as bellow:
#!/usr/bin/python
import MySQLdb
def main():
try:
conn=MySQLdb.connect(host=master ip,user='root',passwd='xxx',db='xxx',port=3306)
cur=conn.cursor()
count = cur.execute('select * from table')
print count
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
if __name__ == "__main__":
main()
however, when I execute it on Agent, there is an error:
Mysql Error 1045: Access denied for user 'root@Agent ip'(using password: YES)
So I don't know why the user is 'root@Agent ip', not the default user of Mysql server on Master. Anyone knows how to solve this problem?
user='root'and mysql useusername@hostas the user, so the user isroot@Agent_ip. It's not an issue ofMySQLdb, you would have the same issue if you log in with a mysql client.