The problem is that I have installed lampp on Ubuntu, and now I have started lampp,
Lampp start
Display is also normal
MySQL connection is normal
Mysql-u root-P
Connect using mysqldb
Import mysqldbdb = mysqldb. Connect (DB = "test ")
Result exception
Traceback (most recent call last): file"
", Line 1, in
File "/usr/lib/python2.7/dist-packages/mysqldb/_ init __. PY ", line 81, in connect return connection (* ARGs, ** kwargs) file"/usr/lib/python2.7/dist-packages/mysqldb/connections. PY ", line 187, in _ init _ super (connection, self ). _ init _ (* ARGs, ** kwargs2) _ mysql_exceptions.operationalerror: (2002, "can't connect to local MySQL server through socket '/var/run/mysqld. sock '(2 )")
For exception display, it calls mysql. sock in the default MySQL installation location, but we use lampp for installation, so we need to specify the location:
Import mysqldbdb = mysqldb. Connect (DB = "test", unix_socket = "/opt/lampp/var/MySQL. Sock ")
OK. Everything is normal.
I'm huangacky. Thank you.