8

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.

Community
  • 1
  • 1
Sal
  • 1,343
  • 4
  • 16
  • 33
  • looks similar to question http://stackoverflow.com/a/27138539/2253302 – alexander.polomodov Mar 07 '16 at 22:01
  • @alexander.polomodov looks similar, but opposite question. That question updates MySQLdb to match `_mysql`, I'm trying to update `_mysql` to match `MySQLdb` (because I need a specific version of `MySQLdb`). There are a bunch of similar questions to the one you posted, but none address the reverse. Also note that some of the comments in that link also ask for help with the reverse. – Sal Mar 07 '16 at 22:56
  • So, the question boils down to "How do I upgrade MySQLdb?" – Rick James Mar 10 '16 at 00:15
  • What version of mysql are you using? The docs explain what _mysql is mysql-python.sourceforge.net/MySQLdb.html#mysql , the last relaese is a couple of years old. You should check out the github page https://github.com/farcepest/MySQLdb1. Also https://dev.mysql.com/downloads/connector/python/ might be of interest – Padraic Cunningham Mar 10 '16 at 13:12
  • What plateform are you running (Debian/red-hat linux?) This is a system dependency problem. – Maresh Mar 14 '16 at 15:11
  • MySQL version: mysql Ver 14.14 Distrib 5.5.46, Ubuntu 14.04.2 LTS – Sal Mar 15 '16 at 20:30

1 Answers1

2

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'
Maggie Ying
  • 9,685
  • 2
  • 31
  • 36
Abhishek Divekar
  • 736
  • 1
  • 11
  • 24
  • 1
    I've tried running the `--upgrade` and I've tried uninstalling and reinstalling. Always MySQLdb 1.2.5 and _mysql 1.2.3. See edit in original post. – Sal Mar 15 '16 at 20:40
  • Okay I think I've got the solution. Please see my answer. – Abhishek Divekar Mar 16 '16 at 15:10
  • This is what I am worried about, going down a long line of dependencies. I'm hesitant to reinstall both `python-dev` and `libmysqlclient-dev`. Uninstalling `MySQLdb` uninstalls `_mysql`, similarly, installing `MySQLdb` installs `_mysql`, which makes me think it is independent of the two packages you mentioned. I'm able to install any version of `MySQLdb` but for some reason I always get v1.2.3 of `_mysql`. – Sal Mar 16 '16 at 15:25
  • Figured out the issue, see my above edits. Thanks for trying to help, I'll give you the bounty for the effort. – Sal Mar 16 '16 at 15:31
  • Ah I see. I was going to make the argument that upgrading is best for dependencies, more stable and less future headaches yadayadayada, but glad you found a solution :) – Abhishek Divekar Mar 16 '16 at 15:34