I am taking my first steps in Python, and struggling to make a connection with a small MySql-database which I have created locally.
My local MySql-database works, and its credentials look like this:enter image description here
It works. I can do anything in a database I would like to.
Now comes the hard part.
When I work with a mysql-connector I use this connection, after which the python-script aborts, Python is closed, and no error messages pop up (i.e. no information):
cnx = mysql.connector.connect(user=’root’, password=’Aragorn_2024′, host=’127.0.0.1′, database=’Aragorn’)
Another trace I have tried is using ODBC, with this connection string. This only gives vague notifications, which I have tried to solve, but without the wanted result.
cnx = pyodbc.connect(‘DRIVER={MySQL ODBC 9.1 Ansi Driver};User ID=root;Password=Aragorn_2024;Server=127.0.0.1;Database=Aragorn;Port=3306;’)
What am I doing wrong, how can I get a working connection?
Thanks in advance.
Joop
I have tried, in both tracks, any combination of passwords, database names, usernames etc. No results.
2
Answers
In reply to Maurice
Using MySql I use this code:
Using ODBC, the code looks like this: import pyodbc cnx = pyodbc.connect('DRIVER={Devart ODBC Driver for SQL Server};Server=127.0.0.1;Database=Aragorn;Port=3306;UserID=root;Password=Aragorn_2024') cur = cnx.cursor() cur.execute("INSERT INTO sakila.tempora SELECT sysdate()") for row in cur.fetchall(): print (row[0]) cnxn.close()
In reply to shadow:
Using the trail with MySql: I get no response at all. Python simply stops, and I have to start it up again from scratch.
Using ODBC, I get:
Or, after adjusting the driver mentioned
pyodbc.Error: (‘HY000’, ‘The driver did not supply an error!’)