close

[Solved] NameError: name ‘_mysql’ is not defined after setting change to mysql

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error NameError: name ‘_mysql’ is not defined after setting change to mysql in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How NameError: name ‘_mysql’ is not defined after setting change to mysql Error Occurs?

Today I get the following error NameError: name ‘_mysql’ is not defined after setting change to mysql in Python.

How To Solve NameError: name ‘_mysql’ is not defined after setting change to mysql Error ?

  1. How To Solve NameError: name '_mysql' is not defined after setting change to mysql Error ?

    To Solve NameError: name '_mysql' is not defined after setting change to mysql Error I was facing the same problem on my MacOS (Big Sur) and I fixed it by doing this cp -r /usr/local/mysql/lib/* /usr/local/lib/

Solution 1

So, I’m answering my own question. Since my blog has database, I gave it a shot to make another project without db, start fresh.

What I noticed was there’s a problem importing MySQLdb module(sub module of mysqlclient) with this traceback: Library not loaded: @rpath/libmysqlclient.21.dylib.

For browsing a few hours I realised that for some reason Mac security setting keeps this from being imported properly.

On mysqlclient library github I found one issue reporting the same as mine. It suggests I run cp -r /usr/local/mysql/lib/* /usr/local/lib/. After this I set settings.py for django.db.backends.mysql, ran python manage.py migrate and it worked. So for empty database, this could be a solution. Still struggling with database one though.

I use

  • MacOS Catalina 10.15.6
  • pyenv

Solution 2

I was facing the same problem on my MacOS (Big Sur) and I fixed it by doing this cp -r /usr/local/mysql/lib/* /usr/local/lib/

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment