1
votes

So I am having a super hard time connecting to a local database using the python mysql.connector module. So I am trying to connect using the highlighted connection. I use the password 'abcdefghijkl'. I am trying to connect to a database named 'flight'

So I am trying to connect using the highlighted connection. I use the password 'abcdefghijkl' to log into the SQL environment. I am trying to connect to a database named 'flight_school'

My python script looks like so. `

import mysql.connector

mydb =mysql.connector.connect("localhost","root","abcdefghijkl","flight_school"") print(mydb.is_connected())

This above code in the arguments in the following order i.e. hostname = localhost, user = 'root', password = 'abcdefghijkl' and database name = 'flight_school'. Its just not working. I get the following error. enter image description here

I would really appreciate some advice, please.

2

2 Answers

1
votes

Please read always the official documentation

Your cooenction stirng has to have this form(if you do it this way=

 mydb = mysql.connector.connect(
     host="localhost",
     user="root",
     passwd="testpaaword",
     database="testdb"
 )
0
votes

Check out SQL-Alchemy module, works wonders from my experience.