Multiple definition of sha1_result
Quick solution: Change all sha1_result functions in Dovecot source tree to dovecot_sha1_result or something. For example:
cd dovecot perl -i -pe 's/sha1_result/dovecot_sha1_result/' `find . -name '*.[ch]'`
More permanent solution: It's a [http://bugs.mysql.com/bug.php?id=13944 MySQL bug]. Upgrade to MySQL 4.1.18 / 5.0.19 when they're out.
If Dovecot can't connect to MySQL but your password is correct, store the password to MySQL with OLD_PASSWORD() function instead of PASSWORD().
[http://www.dovecot.org/list/dovecot/2005-November/010000.html More information here.]
Since the exact same connection code works in simple test programs, this problem probably has something to do with conflicting symbols between Dovecot and MySQL library. I haven't been able to find what exactly causes it though.