MySQLdb and _mysql ncompatible version: how to update _mysql

I run MySQLdb v1.2.3 and get the following error:

LookupError: unknown encoding: utf8mb4 

This answer suggests updating MySQLdb to version 1.2.5. I updated and now get this error:

 ImportError: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is version (1, 2, 3, 'final', 0) 

I'm not sure how to upgrade to _mysql or how this will change my setup. Is it just a python module or is it somehow connected to my MySQL server?

EDIT: I tried using the following three methods:

 sudo pip uninstall mysql-python sudo pip install mysql-python sudo pip uninstall mysql-python sudo pip install mysql-python==1.2.5 sudo pip install mysql-python --upgrade 

When uninstall I get

 /usr/local/lib/python2.7/dist-packages/_mysql.so /usr/local/lib/python2.7/dist-packages/_mysql_exceptions.py /usr/local/lib/python2.7/dist-packages/_mysql_exceptions.pyc Proceed (y/n)? y Successfully uninstalled MySQL-python-1.2.3 

After that, I cannot import MySQLdb or _mysql , but reinstalling always gives me _mysql version 1.2.3.

SECOND EDITING / SOLUTION: Turns _mysql was installed in two different places on the server. Uninstallation / installation, as mentioned above, updated _mysql to v1.2.5, but whenever I imported MySQLdb , priority was given to another version of _mysql that was not affected by pip.

+7
source share
1 answer

According to user manual :

If you want to write applications portable between databases, use MySQLdb and avoid using this module directly. _mysql provides an interface that basically implements the MySQL C API. See the MySQL documentation for more information. The documentation for this module is intentionally weak because you should probably use a higher level MySQLdb module.

Essentially, _mysql is an object-oriented wrapper for the MySQL C API.

This post explains how to use pip to upgrade a single module, a module with all its dependencies, or any combination of them. I think, given the expression, MySQLdb has no dependency on _mysql, and they have not been updated together. Please visit the shared link.

EDIT: After some digging, I found that Ubuntu does not support MySQL, and just pip does not work.

So, I went to this link and did:

apt-get install python-dev libmysqlclient-dev

before doing

sudo pip install MySQL-python

It worked well for me. For you, I think you may need to upgrade or even remove apt-get, and then reinstall the two above-mentioned Ubuntu modules python-dev and libmysqlclient-dev .

For me, this works now when installing for the first time; go to the terminal and enter the python interpreter, then type:

 import MySQLdb MySQLdb.__version__ #I got '1.2.5' import _mysql _mysql.__version__ #Again, I got '1.2.5' 
+2
source

Source: https://habr.com/ru/post/1244606/


All Articles