Unable to Conneqt Mysql server to jupyter notebook due to InterfaceError: (mysql.connector.errors.InterfaceError) 2003:

109 Views Asked by At
Facing Error: (mysql.connector.errors.InterfaceError) 2003: Can't connect to MySQL server on '%-.100s:%u' (%s) (Warning: %u format: a number is required, not str)

(Background on this error at: https://sqlalche.me/e/14/rvf5)

from sqlalchemy import create_engine

# Database connection parameters

```
host = '127.0.0.1'user = 'root'password = 'A2908@bhi'database = 'informatica_mydatabase'
```

```
try:# Create a database engine for MySQLengine = create_engine(f'mysql+mysqlconnector://{user}:{password}@{host}/{database}')
```

```
# Open a connection
connection = engine.connect()

# Define a SQL query
query = "SELECT \* FROM your_table"

# Execute the query
result = connection.execute(query)

# Process the query result
for row in result:
    print(row)
```

except Exception as e:
print(f"Error: {e}")
finally:
\# Close the connection
if 'connection' in locals() and connection is not None:
connection.close()

trying to connect mysql server to Jupyter Notebook

0

There are 0 best solutions below