---
slug: "python3-symbol-not-found-in-flat-namespace-_mysql_affected_rows"
title: "対応方法 When using MySQLdb with Python and encountering \"symbol not found in flat namespace '_mysql_affected_rows'\""
description: "Here is an English translation of the summary for a blog post on how to address the error \"symbol not found in flat namespace '_mysql_affected_rows'\" when attempting to use MySQLdb in Python:\n\n---\n\n**How to Address the \"symbol not found in flat namespace '_mysql_affected_rows'\" Error When Using MySQLdb in Python**\n\nIn this blog post, we will discuss the steps to resolve the error \"symbol not found in flat namespace '_mysql_affected_rows'\" that may occur when attempting to use the MySQLdb library in Python. This error typically arises due to issues with the MySQLdb installation or compatibility problems between the library and your system. We will explore various troubleshooting methods and provide detailed instructions to help you get MySQLdb running smoothly."
url: "https://www.ytyng.com/en/blog/python3-symbol-not-found-in-flat-namespace-_mysql_affected_rows"
publish_date: "2023-11-09T03:39:23Z"
created: "2023-11-09T03:39:23Z"
updated: "2026-02-27T03:14:28.338Z"
categories: ["Django", "Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250503/5d3ab2b6eb504f0dabf659d1a4ef82d3.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/295/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/295/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/295/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/295/featured-music-295-1.mp3", "https://media.ytyng.net/ytyng-blog/295/featured-music-295-4.mp3"]
lang: "en"
---

# 対応方法 When using MySQLdb with Python and encountering "symbol not found in flat namespace '_mysql_affected_rows'"

Attempted to operate MySQL using Python on Apple Silicon, but encountered the following error:

```
ImportError: dlopen(/.../site-packages/MySQLdb/_mysql.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_mysql_affected_rows'
```

Referring to the comment in the following link:

[Macos M1 mysqlclient Symbol not found: _mysql_affected_rows ERROR · Issue #496 · PyMySQL/mysqlclient](https://github.com/PyMySQL/mysqlclient/issues/496#issuecomment-1614688099)

In my environment, the output was:

```shell
% echo $MYSQLCLIENT_LDFLAGS
-L/opt/homebrew/opt/openssl/lib -L/opt/homebrew/opt/mysql/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/lib
```

So, I modified it to:

```shell
% echo $MYSQLCLIENT_LDFLAGS
-L/opt/homebrew/opt/openssl/lib -L/opt/homebrew/opt/mysql/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/lib -lmysqlclient -rpath /opt/homebrew/opt/mysql/lib
```

After that, I executed the following commands:

```shell
pip uninstall mysqlclient
pip cache purge
pip install mysqlclient
```

If there are no errors when executing:

```shell
python3

>>> import MySQLdb
>>>
```

then it's OK.
