Mysql “什么是”呢;“拒绝连接”;python代码的消息?

Mysql “什么是”呢;“拒绝连接”;python代码的消息?,mysql,python-2.7,peewee,Mysql,Python 2.7,Peewee,这是我的密码 import peewee import sqlite3 import pymysql import psycopg2 myDB=peewee.MySQLDatabase("new", host="localhost",port=3306, user="root", passwd="") class MySQLModel(peewee.Model): class Meta: database= myDB class NewPost(MySQLModel): id

这是我的密码

import peewee
import sqlite3
import pymysql
import psycopg2

myDB=peewee.MySQLDatabase("new", host="localhost",port=3306, 
user="root", passwd="")
class MySQLModel(peewee.Model):
class Meta:
    database= myDB

class NewPost(MySQLModel):
   id=peewee.PrimaryKeyField()
   width=peewee.CharField()
   height=peewee.CharField()
   pixel=peewee.CharField()
   image=peewee.CharField()

myDB.connect()

if __name__ =='__main__':
     myDB.create_tables([NewPost])
我无法连接到数据库,因为我收到的错误显示:

OperationalError:(2003,“无法连接到上的MySQL服务器。” “localhost'([Errno 61]连接被拒绝)”)

我找到了解决办法。 第一:我把数据库改成了PostgreSQL 第二:这是我的代码

import psycopg2
import traceback
try:
con=psycopg2.connect(database="elin",user="elin", 
password="8981",host="127.0.0.1",port="5432")
cur=con.cursor()

cur.execute("""
 CREATE TABLE imageinf(
 img_id INT PRIMARY KEY,
 img_url VARCHAR(50) NOT NULL
 );
 """)

con.commit()
print('Create the table DONE ')
con.close()
except psycopg2.Error as e:
print ('I am unable to connect to db')
print(e)
print(e.pgcode)
print(e.pgerror)
print(traceback.format_exc())

检查mysql日志以了解连接被拒绝的原因。请尝试
127.0.0.1
而不是
localhost
。参见和。[注]InnoDB:5.6.38已启动;日志序列号11559969[注意]未找到RSA私钥文件:/Library/Application Support/appsolute/MAMP PRO/db/mysql56//private_key.pem。某些身份验证插件将无法工作。未找到RSA公钥文件:/Library/Application Support/appsolute/MAMP PRO/db/mysql56//public_key.pem。某些身份验证插件将无法工作。[注意]事件计划程序:加载了0个事件[注意]/Applications/MAMP/Library/bin/mysqld:准备连接。版本:“5.6.38”socket:“/Applications/MAMP/tmp/mysql/mysql.sock”端口:0 mysql社区服务器(GPL)