import pymysql
db = pymysql.connect('localhost','root','mkfmkf','mrsoft')
cursor = db.cursor()
cursor.execute('SELECT VERSION')
date = cursor.fetchone()
print('Date:%s'%date)
db.close
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
===================== RESTART: D:\Python\数据库练习\chage.py =====================
Traceback (most recent call last):
File "D:\Python\数据库练习\chage.py", line 2, in <module>
db = pymysql.connect('localhost','root','mkfmkf','mrsoft')
TypeError: __init__() takes 1 positional argument but 5 were given
>>>
报错的是第二行,建议改成这种格式
db = pymysql.connect(host="localhost", user="root", password="xxx", database="xxxx")
self.connect = pymysql.connect(
host = '127.0.0.1',
port = 3306,
user = 'root',
password = '123456',
database = 'eleven',
charset = 'utf8',
)
可以改成上图代码,个人有成功案例,供参考:https://mp.weixin.qq.com/s/ZpprSEpyzRTk2RalGeJRjQ
感谢大家 原因找到了。
缺少一个数据库
运行cmd pip install cryptography