Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I need to use Python to connect to a database that uses the mysql_old_password authentication plugin. I do not have db admin access so I cannot change this setting, so please do not suggest that.

I just installed the MySQLdb module, downloaded here. Other stackoverflow questions on this matter have led me to believe that it is possible to use the old authentication with this module, but when I set up my connection (db info removed for privacy reasons), I get the following error:

('Unexpected error:', <class '_mysql_exceptions.OperationalError'>)
Traceback (most recent call last):
  File "convert_db.py", line 48, in <module>
    main()
  File "convert_db.py", line 25, in main
    prod_con = MySQLdb.connect('xxxx', 'xxxx', 'xxxx', 'xxxx')
  File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2059, "Authentication plugin 'mysql_old_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/mysql_old_password.so, 2): image not found")

This seems to indicate that I just need to download the plugin image from somewhere - is this possible? Or is there some field I can set using MySQLdb that will allow me to connect?

share|improve this question
up vote 1 down vote accepted

mysql_old_password support was removed from the mysql client libraries in 5.7.5, so you're probably using a newer version of the client libraries then that.

You'll have to downgrade your client library version if you need to connect to a server using old password authentication.

You could also try pymysql instead of MySQLdb, which should still have support for old password hashes.

share|improve this answer
    
Okay, I've downgraded to MySQL 5.6, but now when I try to connect I get the following: _mysql_exceptions.OperationalError: (2049, "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)"). This seems to indicate that MySQLdb simply cannot handle the old password hashes - am I correct? – shinytinsmile Aug 10 at 17:27
    
In any case, pymysql does work for my purposes. Thanks so much! – shinytinsmile Aug 10 at 17:42
1  
To disable secure_auth in MySQLdb you'd probably need to create a MySQL config file with secure_auth=off in the [client] section and then pass its path as the read_default_file argument to connect(). But using pymysql instead is probably the more portable solution anyway – mata Aug 10 at 18:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.