import pymysql db = pymysql.connect(host = 'localhost',user = 'root',password =
'asdfgh',port = 3306) cursor = db.cursor() cursor.execute('SELECT VERSION()')
data = cursor.fetchone() print('database version:',data) cursor.execute('CREATE
DATABASE spiders DEFAULT CHARACTER SET utf8') db.close()


解决方法:

1.打开cmd命令行窗口,输入cd C:\Program Files (x86)\MySQL\MySQL Server
5.7\bin,回车进入该目录下。(这个是你的mysql的目录下的bin文件夹)

2.输入mysql -hlocalhost -uroot -p,回车再输入密码,然后连接mysql

3.输入ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY
'你的密码';回车就修改成功了



最后再次运行代码即可出现

database version: ('8.0.11',)