Issue: ImproperlyConfigured: MySQL driver not installed!
Author: MatthewKosloski
State: closed
Created: 2018-04-13 02:47:04

Hey, guys.  I'm trying to connect to my remote MySQL database using Peewee, but I am getting the following error (in a virtual environment):

```
Traceback (most recent call last):
  File "peewee_test.py", line 2, in <module>
    from student import Student
  File "/Users/Matthew/Desktop/python-mvc/student.py", line 10, in <module>
    db.connect()
  File "/Users/Matthew/Desktop/python-mvc/lib/python3.6/site-packages/peewee.py", line 2467, in connect
    self._state.set_connection(self._connect())
  File "/Users/Matthew/Desktop/python-mvc/lib/python3.6/site-packages/peewee.py", line 3164, in _connect
    raise ImproperlyConfigured('MySQL driver not installed!')
peewee.ImproperlyConfigured: MySQL driver not installed!
```

student.py

```
from peewee import *

db = MySQLDatabase(
	host='host_here',
	user='mysql_username_here',
	password='mysql_password_here',
	database='mysql_db_here'
)

db.connect()

class Student(Model):
	firstName = CharField()
	lastName = CharField()

	class Meta:
		database = db
```

peewee_test.py

```
from peewee import *
from student import Student

john_doe = Student.create(
	firstName='John', 
	lastName='Doe',
	is_relative=False
)
```

I installed MySQL via Homebrew.  This is the version I have:

```
mysql  Ver 14.14 Distrib 5.7.12, for osx10.10 (x86_64) using  EditLine wrapper
```

I also installed `PyMySQL` as others have suggested [here](https://github.com/coleifer/peewee/issues/390#issuecomment-48612520).  Others also suggested installing `mysql-python`, but I get an error when when attempting to install it:
```
Collecting mysql-python
  Using cached MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/m7/wyjxzv8s5sdbh2jr35tq55y00000gn/T/pip-build-xh7783h6/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/var/folders/m7/wyjxzv8s5sdbh2jr35tq55y00000gn/T/pip-build-xh7783h6/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/m7/wyjxzv8s5sdbh2jr35tq55y00000gn/T/pip-build-xh7783h6/mysql-python/
```

I have two installations of Python on My Mac (running OSX 10.10): Python 2.7 and 3.6.  I'm using `pip3` to install the above packages.

Thank you for your time!

Peewee will work with `pymysql` or `mysql-python`. It sounds like you have an issue with your module-import path. This is not an issue with Peewee -- I'd suggest trying StackOverflow.

`mysqlclient` is recommend

So for mysql:

* [pymysql](https://github.com/PyMySQL/PyMySQL) is a pure-python mysql client, works with python 2 and 3. Peewee will use attempt to use pymysql first.
* [mysqlclient](https://github.com/PyMySQL/mysqlclient-python) uses a c extension and supports python 3. It exposes a `MySQLdb` module. Peewee will attempt to use this module if pymysql is not installed.
* `mysql-python` is also called [MySQLdb1](https://github.com/farcepest/MySQLdb1) and is legacy and should not be used. Since this shares the same module name as mysqlclient, same applies.
* [mysql-connector python](https://github.com/mysql/mysql-connector-python) pure-python (I think??) supports python 3. To use this driver you can use `playhouse.mysql_ext.MySQLConnectorDatabase`.

@weaming mysqlclient did not seem to work in my case.
@coleifer -- `pymysql` worked without issue on first attempt.
Thanks!

> @weaming mysqlclient did not seem to work in my case.
> @coleifer -- `pymysql` worked without issue on first attempt.
> Thanks!

`mysqlclient` further depends on some other dependencies, as stated in the [official doc](https://github.com/PyMySQL/mysqlclient-python), . It depends on which OS you are using, slight difference between macOS and Ubuntu, for instance.