mysql.connector.errors.OperationalError:2055:与“主机”上的mysql服务器失去连接,系统错误:32断开管道

2024-09-29 23:33:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将Heroku与ClearDB插件一起使用,一切都正常。这不是真正的问题,因为这也发生在我的电脑上。我正在制作一个discord.py bot,它使用SQL保存2个变量。成员的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我应该怎么做?我想重新启动数据库,但我不知道如何安全地重新启动,也不知道需要多长时间。我该怎么办


Tags: tosendformatmessagedbvaluehavechannel

热门问题