db=MySQLdb.connect( user="root" ,passwd="" ,db="my_db" ,unix_socket="/opt/lampp/var/mysql/mysql.sock")I'm attempting to use mysql after only having worked with sqlite in the past.I've installed XAMPP on Linux (ubuntu) and have mysql up and running fine (seems like that with phpMyadmin at least). However, I'm having trouble getting the MySQLdb (the python lib) working {installed this using apt}.to be exact:>>> import MySQLdb>>> db = MySQLdb.connect(host="localhost",db="opfine")Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/lib/pymodules/python2.6/MySQLdb/__init__.py", line 81, in Connect return Connection(*args, **kwargs) File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 170, in __init_ ... super(Connection, self).__init__(*args, **kwargs2)I'm guessingmeans its expecting some sort of local installation (i.e. not within XAMPP), but I can't figure out how to go about modding this to get it to work with the XAMMP flavor of mysql.Help is much appreciated! 解决方案 For the record (and thanks to a pointer from Igancio), I found that the below works (terrible I didn't think of this before):db=MySQLdb.connect( user="root" ,passwd="" ,db="my_db" ,unix_socket="/opt/lampp/var/mysql/mysql.sock") 这篇关于通过Python访问XAMPP mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 13:02