---
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-05-26T14:11:00.983Z"
categories: ["Django", "MySQL", "Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20260526/c5eba818c2474f93a7a1687259324a8f.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/181/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/181/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/181/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/181/featured-music-181-1.mp3", "https://media.ytyng.net/ytyng-blog/181/featured-music-181-2.mp3"]
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>
