安装了python-mysql。准备连接数据库。输入命令
>>> import MySQLdb
>>> cxn =MySQLdb.connect(user='root')
Traceback (mostrecent call last):
File "<stdin>", line 1, in<module>
File"/usr/lib/pymodules/python2.6/MySQLdb/__init__.py", line 81, inConnect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py",line 170, in __init__
super(Connection, self).__init__(*args,**kwargs2)
_mysql_exceptions.OperationalError:(2002, "Can't connect to local MySQL server through socket'/var/run/mysqld/mysqld.sock' (2)")
结果出现"Can't connect to local MySQL server through socket'/var/run/mysqld/mysqld.sock' (2)"。
原因是mysql服务器未安装,在ubuntu可以使用apt-get install mysql-server来安装mysql服务器。