Troubleshooting of MySQL server problems in connecting to lampp using Python-mysqldb. Connect

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.