D
D
drqqv2021-12-14 04:27:45
MySQL
drqqv, 2021-12-14 04:27:45

MySQL error. How to decide?

Gives an error message:

raise errors.OperationalError("MySQL Connection not available.")
mysql.connector.errors.OperationalError: MySQL Connection not available.


The code:
from getpass import getpass
from mysql.connector import connect, Error

try:
    with connect(
            host="localhost",
            user="root",
            password="Current-Root-Password",
            database="valen_bot"
    ) as connection:
        print(connection)
except Error as e:
    print(e)


show_table_query = "valen_info"
with connection.cursor() as cursor:
    cursor.execute(show_table_query)
    # Fetch rows from last executed query
    result = cursor.fetchall()
    for row in result:
        print(row)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hanneman, 2021-12-14
@Hanneman

Well, who knows - you don't give details. Maybe you don't have MySQL on localhost. It may be that Current-Root-Password is used as a password, but you do not notice. Or maybe access to the database is denied with a password from localhost (which is unlikely, but still). What is "valen_info" in general - where was this code copied from in general?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question