Python操作Mysql,Python连接Mysql数据库方法


python连接MYSQL数据方法:

print("开始连接ing")
try:
    conn=MySQL.connect(host="127.0.0.1",port=3306,user="root",passwd="root",db="tomato",charset='utf8')
    #charset解决字符乱码
except:
    print("连接失败!")
cur = conn.cursor()
print("连接成功!!!")