---
slug: "python-name-error-mysql-_mysql-is-not-defined"
title: "NameError: name '_mysql' is not defined in Python (Django) (Especially During Local Development)"
description: "If a Django project that has been working until now fails to start after a long time with the following error:\n```\nversion_info, _mysql.version_info, _mysql.__file__\nNameError: name '_mysql' is not defined\n```\n"
url: "https://www.ytyng.com/en/blog/python-name-error-mysql-_mysql-is-not-defined"
publish_date: "2020-10-11T02:52:50Z"
created: "2020-10-11T02:52:50Z"
updated: "2026-02-27T06:54:54.306Z"
categories: ["Django", "MySQL", "Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20240323/9878004257e34000a1053b1b2b4f631a.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# NameError: name '_mysql' is not defined in Python (Django) (Especially During Local Development)

<p class="p1">I tried to start a Django project that had been working fine before, but after a long time, I encountered the following error:</p>
<p class="p1"></p>
<pre class="p1">version_info, _mysql.version_info, _mysql.__file__<br />NameError: name '_mysql' is not defined</pre>
<p class="p1">If this happens, it means the project won't start.</p>
<p class="p1"></p>
<p class="p1">This issue is caused by an update to the MySQL library outside of the Python project, which breaks the link from the mysqlclient within the project.</p>
<p class="p1">This is likely due to running a command like brew install mysql-client.</p>
<p class="p1"></p>
<p class="p3">You can resolve this issue by reinstalling <span class="s1">mysqlclient</span>.</p>
<p class="p3"></p>
<pre class="p1">pip install --force-reinstall mysqlclient</pre>
