从已建立的mysql连接中获取用户

问题描述 投票:0回答:1

我已经使用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

python mysql-python
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.