|
這本書的第三章第六節 MySQL資料庫的操作 前面需叫我們下載UniformServer 開啟phymyadmin建立資料庫 但好像沒辦法連線 程式是這樣 import pymysql conn = pymysql.connect('localhost',port=3306,user='root',passwd='1234',charset='utf8', db='pythondb') #連結資料庫
with conn.cursor() as cursor: sql = """ CREATE TABLE IF NOT EXISTS Scores ( ID int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20), Chinese int(3), English int(3), Math int(3) ); """ cursor.execute(sql) #執行SQL指令 conn.commit() #提交資料庫 conn.close()
但問題 TypeError Traceback (most recent call last) <ipython-input-7-f7ae04f4eb60> in <module> 1 import pymysql ----> 2 conn = pymysql.connect('localhost',port=3306,user='root',passwd='1234',charset='utf8', db='pythondb') #連結資料庫 3 4 with conn.cursor() as cursor: 5 sql = """
TypeError: __init__() takes 1 positional argument but 2 positional arguments (and 5 keyword-only arguments) were given
然後UniformServer會有電腦拒絕連線的問題 |