时间:2021-07-01 10:21:17 帮助过:12人阅读
目前MySQLdb不支持python3.x.可以使用MySQL connnecter代替。
import mysql.connector import sys user = ‘root‘ pwd = ‘root‘ host = ‘20.0.2.50‘ db=‘mysql‘ create_tab_sql = "CREATE TABLE IF NOT EXISTS TAB_TEST( TAB_NAME VARCHAR(20), CITY_NAME VARCHAR(20)) CHARACTER SET utf8" conn = mysql.connector.connect(user=user,password=pwd,host=host,database=db) cursor = conn.cursor() try: cursor.execute(create_tab_sql) except mysql.connector.Error as err: print("create table ‘tab_test‘ failed.") print("Error:{}".format(err.msg)) sys.exit()
本文出自 “LIBYDWEI” 博客,请务必保留此出处http://libydwei.blog.51cto.com/37541/1774772
Python3 连接Mysql数据库
标签:电子书 数据库 python 网上