I'm running MySQLdb v1.2.3 and getting the following error:
LookupError: unknown encoding: utf8mb4
This answer suggests updating MySQLdb to version 1.2.5. I updated and am now getting 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 go about updating _mysql
or how this will change my setup. Is this just a python module or is it connected in some way to my MySQL server?
EDIT: I've tried running 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 uninstalling 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 am unable to import either MySQLdb
or _mysql
but reinstalling always gives me _mysql
version 1.2.3.
SECOND EDIT / SOLUTION: Turns out _mysql
was installed in two different places on the server. Uninstalling/installing, as above, upgraded _mysql
to v1.2.5 but whenever I then imported MySQLdb
precedence was given to the other version of _mysql
which was not being touched by pip.
According to the user manual:
If you want to write applications which are portable across databases, use MySQLdb, and avoid using this module directly. _mysql provides an interface which mostly implements the MySQL C API. For more information, see the MySQL documentation. The documentation for this module is intentionally weak because you probably should use the higher-level MySQLdb module.
Basically, _mysql is an object-oriented wrapper for the MySQL C API.
This post explains how to use pip to upgrade one module, a module with all its dependencies, or any combination thereof. I think that, given the statement, MySQLdb does not have a dependency on _mysql, and they were not upgraded together. Please visit the link shared.
EDIT: After some digging, I found that Ubuntu does not support MySQL nicely, and just pip doesn't work.
So I went to this link and did:
apt-get install python-dev libmysqlclient-dev
before doing
sudo pip install MySQL-python
This worked nicely for me. For you, I think you may need to upgrade or even apt-get remove and then reinstall the above two Ubuntu modules python-dev
and libmysqlclient-dev
.
For me, it's working now when installing for the first time; go to a 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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With