Posted on

ImproperlyConfigured: MySQL driver not installed

You may refer to MySQL API Dependency Installation to install the MySQL Drivers.

This issue is stated at ImproperlyConfigured: MySQL driver not installed! · Issue #1569 · coleifer/peewee

Authentication plugin ‘caching_sha2_password’ cannot be loaded

One way to solve this is to login to the database and change the password to legacy mode for the particular user, for example

 alter user 'username'@'%' identified with mysql_native_password by 'your_password';

This should properly solve the problem.

  • % means remote user, it can be replaced by localhost for local users.

pymysql.err.InterfaceError: (0, ”) or peewee.OperationalError: (2006, ‘MySQL server has gone away’)

If you are using the pymysql API, it will be pymysql.err.InterfaceError: (0, ''), or if you are using mysqlclient, it’s peewee.OperationalError: (2006, 'MySQL server has gone away').

The problem happens because the SQL long connection is broken, and peewee by default manages the connection for you, and it does not reconnect when the connection is broken.

To solve this problem, you may handle all of these connections manually. peewee does provide mixin for this purpose.

# init the SQL database
db = MySQLDatabase(...)

@db.connection_context()
def some_sql_operation_utility():
  # perform some transaction here

With the connection_context()method for MySQLDatabase class as a mixin, the connection can be re-established and closed explicitly, thus eliminating the issue.

References

  1. https://stackoverflow.com/questions/49194719/authentication-plugin-caching-sha2-password-cannot-be-loaded
  2. ImproperlyConfigured: MySQL driver not installed! · Issue #1569 · coleifer/peewee
  3. http://docs.peewee-orm.com/en/latest/peewee/database.html#context-managers

Leave a Reply

Your email address will not be published. Required fields are marked *