python3循环通过一系列DB,然后连接
我正在尝试循环浏览许多具有相同连接信息的MySQL主机,并在它们中执行相同的查询&获取结果。
我仍在学习Python&陷入以下内容;
import pymysql
ENDPOINTS=['endpoint01', 'endpoint02', 'endpoint03', 'endpoint04']
USER="SOME_USER"
PASS="SOME_PASSWORD"
print("Testing")
for x in ENDPOINTS:
# Open database connection
DATAB = pymysql.connect(x,USER,PASS)
cursor = DATAB.cursor()
cursor.execute("show databases like 'THIS%'")
data = cursor.fetchall()
print (data)
DATAB.close()
这是我收到的错误;
DATAB = pymysql.connect(x,USER,PASS)
TypeError: __init__() takes 1 positional argument but 4 were given
I am trying to loop through a number of mysql hosts which have the same connection info and execute the same query on each of them & fetch the results.
I'm still learning python & am stuck on the following;
import pymysql
ENDPOINTS=['endpoint01', 'endpoint02', 'endpoint03', 'endpoint04']
USER="SOME_USER"
PASS="SOME_PASSWORD"
print("Testing")
for x in ENDPOINTS:
# Open database connection
DATAB = pymysql.connect(x,USER,PASS)
cursor = DATAB.cursor()
cursor.execute("show databases like 'THIS%'")
data = cursor.fetchall()
print (data)
DATAB.close()
And this is the error I receive;
DATAB = pymysql.connect(x,USER,PASS)
TypeError: __init__() takes 1 positional argument but 4 were given
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在错误地传递参数。尝试
datab = pymysql.connect(host = x,user = user = user = uses,password = pass)
:You're passing the parameters incorrectly. Try
DATAB = pymysql.connect(host=x,user=USER,password=PASS)
: