1

I am using Heroku with the ClearDB add-on and it all works. This isn't really the problem, because this also happens in my PC. I am making a discord.py bot that saves 2 variables using SQL. The ID of the member, and the amount of 'thing' they have. Here is an example of my code.

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

and now, this is how I use it.

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]))

As simple as that. But after I use this command a few times, It bring this error and doesn't allow me to use any other command that uses SQL: mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'host', system error: 32 Broken pipe What should I do? I want to restart the database, but I don't know how to do it safely and don't know how much time it will use. What should I do?

Yousef Nashwan
  • 25
  • 2
  • 11
  • Would this be any use to you? https://stackoverflow.com/questions/60286623/python-loses-connection-to-mysql-database-after-about-a-day – Kelo Feb 01 '21 at 11:50
  • My problem is already fixed. And to fix that problem, I used the same method you mention. Thank you for your time. – Yousef Nashwan Feb 02 '21 at 13:31

0 Answers0