写一段python代码,连接mysql,并获取每一个数据库的名称、表的名称和列的名称。
时间: 2023-03-19 14:20:57 浏览: 121
import mysql.connectormydb = mysql.connector.connect(
host="localhost",
user="yourusername",
passwd="yourpassword"
)mycursor = mydb.cursor()mycursor.execute("SHOW DATABASES")for x in mycursor:
print(x)mycursor.execute("SHOW TABLES")for x in mycursor:
print(x)mycursor.execute("SHOW COLUMNS FROM table_name")for x in mycursor:
print(x)
阅读全文