I am using the mysql-connector-python library of mysql to try to connect to the MariaDB database of other devices in the local area network, but it failed, and it exited directly without outputting any error messages.
Problem Description Software version:
MariaDB server 10.11.6
mysql-connector-python 9.2.0
MariaDB server, IP is 192.168.1.60
Client, IP is 192.168.1.35
Python code is as follows:
import mysql.connector import logging # Configure logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') try: logging.info("Connecting to the database...") connection = mysql.connector.connect( host="192.168.1.60", port=3306, user="mysql", password="xxx") logging.info("Connection established.") # Create a cursor object to execute SQL queries cursor = connection.cursor() # Get all databases logging.info("Executing SHOW DATABASES query...") cursor.execute("SHOW DATABASES") # Print all databases and the table names in each database for (database,) in cursor.fetchall(): logging.info(f"Database: {database}") # Switch to the current database cursor.execute(f"USE {database}") # Get and print all tables in the current database cursor.execute("SHOW TABLES") for (table,) in cursor.fetchall(): logging.info(f" Table: {table}") # Close the cursor and connection cursor.close() connection.close() logging.info("Connection closed.") except mysql.connector.Error as err: logging.error(f"Error: {err}") except Exception as e: logging.error(f"Unexpected error: {e}") After running this code, it exits directly without outputting any error messages.
...