10

I'm trying to connect to a local mysql DB on my windows machine using sqlalchemy. It works using pymysql, but not with sqlalchemy.

Code sqlalchemy:

engine = create_engine('mysql+mysqldb://root:mypass@localhost/classicmodels')
engine.connect()

Gives error:

OperationalError: (_mysql_exceptions.OperationalError) (1193, "Unknown system variable 'tx_isolation'")

Working code, using pymysql:

connection = pymysql.connect(host='localhost',
                             user='root',
                             password = 'mypass',
                             db = 'classicmodels')

cursor = connection.cursor()

cursor.execute('select * from customers')
mydata = cursor.fetchall()
mydata = pd.DataFrame(list(mydata))
mydata.head(5)
3
  • You're using the MySQLdb driver with SQLA. What if you use pymysql with it as well (mysql+pymysql://...)? Commented May 3, 2018 at 14:23
  • Thanks but that does not work either Commented May 4, 2018 at 11:33
  • What version of MySQL etc. are you using? Also please include the full traceback, not just the error message. Commented May 4, 2018 at 13:24

2 Answers 2

15

I ran into a similar error involving tx_isolation.

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1193, "Unknown system variable 'tx_isolation'")

This was due to using an old version of SQLAlchemy.

pip install --upgrade SQLAlchemy

I was running off v1.0.15, upgrading to v1.2.9 fixed the error for me. I am also using the mysql+pymysql connection setting as mentioned above.

Sign up to request clarification or add additional context in comments.

1 Comment

I upgraded from 1.1.13 to 1.2.15 and had/fixed this error.
6

What's your version of sqlalchemy? Try to use the newest one, because the 8.0 version of mysql has depreciated 'tx_isolation'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.