我已经使用MySQLdb
python库建立了MySQL连接。由于初始连接发生在完全不同的地方,因此我想从给定的MySQLdb.connections.Connection
对象中获取用户名。
在研究了源代码和进行了一些测试之后,我没有找到任何方法来获取用户名。
import MySQLdb
import MySQLdb.cursors
db = MySQLdb.connect(
host=host,
user=user,
passwd=passwd,
db=dbname,
use_unicode=True,
charset="utf8mb4",
cursorclass=MySQLdb.cursors.DictCursor
)
try:
print(db.user)
except Exception as e:
print(e)
输出:
AttributeError: 'Connection' object has no attribute 'user'
有没有办法获得这种属性?
版本:
MySQLdb:1.4.2.post1
Python:2.7