首页 > 解决方案 > mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'host', system error: 32 Broken pipe

问题描述

我将 Heroku 与 ClearDB 插件一起使用,一切正常。这不是真正的问题,因为这也发生在我的电脑上。我正在制作一个使用 SQL 保存 2 个变量的 discord.py 机器人。成员的 ID,以及他们拥有的“事物”数量。这是我的代码示例。

db = mysql.connector.connect(
host="host",
user="user",
passwd="passwd",
database="database"
)
mycursor = db.cursor()

现在,这就是我使用它的方式。

if message.content.startswith('.add '):
    try:
        auth3 = discord.utils.get(message.guild.roles, name="auth ")
        messagehere = str(message.content)
        warnedmemberun = str(message.content)[8:]
        warnedmember = warnedmemberun.partition(">")[0]
        user = await message.guild.fetch_member(warnedmember)
        if auth3 in user.roles:
            await message.channel.send("{}, don't try add value to him.".format(message.author.mention))
        else:
            if auth3 in message.author.roles:
                warnedfor = messagehere.split(">",1)[1]
                subit = int(warnedfor)
                mycursor.execute("SELECT value FROM Profile WHERE name=%s", (user.id,))
                value = mycursor.fetchall()
                channel = message.channel
                shareformat = str(value[0])[:-2][1:]
                shareint = int(shareformat)
                shareint += subit
                mycursor.execute("""UPDATE Profile SET value=%s WHERE name=%s""", (shareint, user.id,))
                await message.author.send("You have given {} value to {}. He now has {} value.".format(subit, user, shareint))
                await user.send("{} value have been given to you by {}. You now have {} value.".format(subit, message.author, shareint))
                db.commit()
            else:
                await message.author.send("You do not have enough perms to do that!")
    except IndexError as e:
        print(e)
        await message.channel.send("{}, something went wronge. Check your formatting and make sure the user exists.".format(str(message.author)[:-5]))

就如此容易。但是在我使用这个命令几次之后,它带来了这个错误并且不允许我使用任何其他使用 SQL 的命令:mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'host', system error: 32 Broken pipe我该怎么办?想重启数据库,但是不知道怎么安全,也不知道会用多少时间。我应该怎么办?

标签: pythonmysqldatabasediscord.py

解决方案


推荐阅读