马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pymysql
db=pymysql.connect(host='localhost',user='root',password='123456',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()
C:\Users\tiger\PycharmProjects\spider\venv\Scripts\python.exe C:/Users/tiger/PycharmProjects/spider/temp.py
Traceback (most recent call last):
File "C:\Users\tiger\PycharmProjects\spider\venv\lib\site-packages\pymysql\connections.py", line 583, in connect
**kwargs)
File "C:\Users\tiger\Anaconda3\lib\socket.py", line 728, in create_connection
raise err
File "C:\Users\tiger\Anaconda3\lib\socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/tiger/PycharmProjects/spider/temp.py", line 3, in <module>
db=pymysql.connect(host='localhost',user='root',password='123456',port=3306)
File "C:\Users\tiger\PycharmProjects\spider\venv\lib\site-packages\pymysql\__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "C:\Users\tiger\PycharmProjects\spider\venv\lib\site-packages\pymysql\connections.py", line 325, in __init__
self.connect()
File "C:\Users\tiger\PycharmProjects\spider\venv\lib\site-packages\pymysql\connections.py", line 630, in connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([WinError 10061] 由于目标计算机积极拒绝,无法连接。)")
Process finished with exit code 1
求解,求更正 |