无法连接到MySQL和PostgreSQL
我尝试使用Jupiter笔记本连接MySQL和PostgreSQL。我不知道为什么它不再起作用了。错误消息是“error:root:inspect模块中的内部Python错误”。 下面是此内部错误的回溯。 起初,我使用sqlite3链接数据库没有问题 下面是我使用squlite3的代码无法连接到MySQL和PostgreSQL,mysql,postgresql,connection,localhost,local,Mysql,Postgresql,Connection,Localhost,Local,我尝试使用Jupiter笔记本连接MySQL和PostgreSQL。我不知道为什么它不再起作用了。错误消息是“error:root:inspect模块中的内部Python错误”。 下面是此内部错误的回溯。 起初,我使用sqlite3链接数据库没有问题 下面是我使用squlite3的代码 pitchfork_db = sqlite3.connect("pitchfork.db") reviews.to_sql('reviews', pitchfork_db, index=F
pitchfork_db = sqlite3.connect("pitchfork.db")
reviews.to_sql('reviews', pitchfork_db, index=False, if_exists='replace')
artists.to_sql('artists', pitchfork_db, index=False, if_exists='replace')
content.to_sql('content', pitchfork_db, index=False, if_exists='replace')
genres.to_sql('genres', pitchfork_db, index=False, if_exists='replace')
labels.to_sql('labels', pitchfork_db, index=False, if_exists='replace')
years.to_sql('years', pitchfork_db, index=False, if_exists='replace')
I can perform the query I want to
pitchfork_cursor = pitchfork_db.cursor()
pitchfork_cursor.execute("SELECT title, artist, score FROM reviews WHERE
score=10")
colnames = [x[0] for x in pitchfork_cursor.description]
pitchfork_df = pitchfork_cursor.fetchall()
pd.DataFrame(pitchfork_df, columns=colnames)
我使用MySQL收到错误消息:
“回溯(最近一次呼叫最后一次):
ConnectionRefusedError:[WinError 10061]无法建立连接,因为目标计算机主动拒绝它”
以下是我的MySQL代码:
import mysql.connector
mysqlpassword = os.getenv("mysqlpassword")
dbserver = mysql.connector.connect(
user='root',
passwd=mysqlpassword,
host="localhost"
)
我使用PostgreSQL收到错误消息:
“回溯(最近一次呼叫最后一次):
psycopg2.OperationalError:无法连接到服务器:连接被拒绝(0x0000274D/10061)
服务器是否在主机“localhost”(::1)上运行并接受“
这是我写给PostgreSQL的代码
import psycopg2
pgpassword = os.getenv("pgpassword")
dbserver = psycopg2.connect(
user='postgres',
password=pgpassword,
host="localhost"
)
dbserver.autocommit = True
我在这里呆了几个小时,任何评论都会很棒!谢谢大家! 您是否在代码的其他地方使用
inspect
?也没有看到回溯。两个连接器都应该尝试使用套接字,但都失败了。