title: NameError: name '_mysql' is not defined after setting change to mysql
body: <p>I have a running Django blog with sqlite3 db at my local machine. What I want is to</p>
  <ol>
  <li>convert sqlite3 db to mysql db</li>
  <li>change Django settings.py file to serve MySQL db</li>
  </ol>
  <p>Before I ran into the first step, I jumped into the second first. I followed <a href="https://www.digitalocean.com/community/tutorials/how-to-create-a-django-app-and-connect-it-to-a-database" rel="nofollow noreferrer">this web page</a> (on MacOS). I created databases called <code>djangolocaldb</code> on root user and have those infos in <code>/etc/mysql/my.cnf</code> like this:</p>
  <pre><code># /etc/mysql/my.cnf
  
  [client]
  database=djangolocaldb
  user=root
  password=ROOTPASSWORD
  default-character-set=utf8
  </code></pre>
  <p>Of course I created db, but not table within it.</p>
  <pre><code>mysql&gt; show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | djangolocaldb      |
  | employees          |
  | information_schema |
  | mydatabase         |
  | mysql              |
  | performance_schema |
  | sys                |
  +--------------------+
  7 rows in set (0.00 sec)
  </code></pre>
  <p>I changed <code>settings.py</code> like this as the web page suggested. Here's how:</p>
  <pre><code># settings.py
  
  ...
  
  # Database
  # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
  
  DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.mysql',
              #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
              'OPTIONS' : {
                  'read_default_file': '/etc/mysql/my.cnf',
                  }
              }
          }
  
  ...
  </code></pre>
  <p>Now, when I run <code>python manage.py runserver</code> with my <code>venv</code> activated, I got a brutal traceback like this(I ran <code>python manage.py migrate</code> first, and the traceback looked almost the same anyway):</p>
  <pre><code>(.venv) ➜  django-local-blog git:(master) ✗ python manage.py runserver
  Watching for file changes with StatReloader
  Exception in thread django-main-thread:
  Traceback (most recent call last):
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/MySQLdb/__init__.py&quot;, line 18, in &lt;module&gt;
      from . import _mysql
  ImportError: dlopen(/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib
    Referenced from: /Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
    Reason: image not found
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/Users/gwanghyeongim/.pyenv/versions/3.7.6/lib/python3.7/threading.py&quot;, line 926, in _bootstrap_inner
      self.run()
    File &quot;/Users/gwanghyeongim/.pyenv/versions/3.7.6/lib/python3.7/threading.py&quot;, line 870, in run
      self._target(*self._args, **self._kwargs)
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/utils/autoreload.py&quot;, line 53, in wrapper
      fn(*args, **kwargs)
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py&quot;, line 109, in inner_run
      autoreload.raise_last_exception()
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/utils/autoreload.py&quot;, line 76, in raise_last_exception
      raise _exception[1]
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/core/management/__init__.py&quot;, line 357, in execute
      autoreload.check_errors(django.setup)()
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/utils/autoreload.py&quot;, line 53, in wrapper
      fn(*args, **kwargs)
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/__init__.py&quot;, line 24, in setup
      apps.populate(settings.INSTALLED_APPS)
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/apps/registry.py&quot;, line 114, in populate
      app_config.import_models()
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/apps/config.py&quot;, line 211, in import_models
      self.models_module = import_module(models_module_name)
    File &quot;/Users/gwanghyeongim/.pyenv/versions/3.7.6/lib/python3.7/importlib/__init__.py&quot;, line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1006, in _gcd_import
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983, in _find_and_load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 967, in _find_and_load_unlocked
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 677, in _load_unlocked
    File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 728, in exec_module
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/contrib/auth/models.py&quot;, line 2, in &lt;module&gt;
      from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/contrib/auth/base_user.py&quot;, line 47, in &lt;module&gt;
      class AbstractBaseUser(models.Model):
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/db/models/base.py&quot;, line 121, in __new__
      new_class.add_to_class('_meta', Options(meta, app_label))
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/db/models/base.py&quot;, line 325, in add_to_class
      value.contribute_to_class(cls, name)
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/db/models/options.py&quot;, line 208, in contribute_to_class
      self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/db/__init__.py&quot;, line 28, in __getattr__
      return getattr(connections[DEFAULT_DB_ALIAS], item)
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/db/utils.py&quot;, line 207, in __getitem__
      backend = load_backend(db['ENGINE'])
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/db/utils.py&quot;, line 111, in load_backend
      return import_module('%s.base' % backend_name)
    File &quot;/Users/gwanghyeongim/.pyenv/versions/3.7.6/lib/python3.7/importlib/__init__.py&quot;, line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/django/db/backends/mysql/base.py&quot;, line 16, in &lt;module&gt;
      import MySQLdb as Database
    File &quot;/Users/gwanghyeongim/Documents/py/coreyMS_pj/django-local-blog/.venv/lib/python3.7/site-packages/MySQLdb/__init__.py&quot;, line 24, in &lt;module&gt;
      version_info, _mysql.version_info, _mysql.__file__
  NameError: name '_mysql' is not defined
  </code></pre>
  <p>So this <code>NameError: name '_mysql' is not defined</code> is the problem. I installed <code>mysqlclient</code> before, changed <code>settings.py</code>, made db in mysql, but none of the steps made it any helpful yet.</p>
  <p>And I noticed that even I changed my <code>settings.py</code> back to sqlite3, my blog spit the same <em>_mysql not defined error</em>. So I ended up reverting my commit and now I'm back to sqlite3 (at least my blog is running with it).</p>
  <p>I'm guessing it could be that I didn't convert data first, but I'm not 100% sure of it.</p>
  <p>Any suggestion would be much appreciated. Thank you in advance!</p>