|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import pymysql
- import sys
- #============================连接数据库
- try:
- conn=pymysql.connect(host='localhost', user='root', passwd='mysql123', db='test', port=3306,
- charset='utf8')
- except:
- print("打开数据库连接出错,请检查!")
- conn.close()
- sys.exit()
- #============================判断表是否存在,不存在时建立新表
- cur=conn.cursor()
- sql='''create table if not exists T_fish
- (date1 char(12) primary key not null,
- name char(10) not null,
- nums int not null,
- price decimal(10,2) not null,
- sExplain varchar(200));'''
- try:
- cur.execute(sql)
- conn.commit()
- print("T_fish表可以使用!")
- except:
- print("T_fish表是否建立过程出错!")
- conn.close()
复制代码
总是提示'打开数据库链接出错,请检查'
text也建立了,求大佬指点
你肯定是没连接上,单独运行try内部的语句,看看到底提示什么
|
|