[Very depressing] python2.7 connects to mysql5.5 configuration, python2.7mysql5.5

Source: Internet
Author: User

[Very depressing] python2.7 connects to mysql5.5 configuration, python2.7mysql5.5

Today, the python version on the company's computer is the same as that on the home computer. It is different from the mysql 5.6 version. It took two days to complete the configuration of python and mysql.

To put it simply, python always reports the 2003 error when connecting to mysql. The error code is: (2003, "Can't, connect to MySQL server on 'localhost' (10061 )"

After a day on the internet, Baidu still failed to find a solution. It seems that its configuration has changed since mysql5.6. After mysql service is started on the company's computer, enter netstat-ano in cmd to check the mysql port usage, the result shows that its localadress is: 1, which seems to be an ipv6 address. So far, I don't know how to solve it.

When I got home, I thought a senior on the Internet said that I could not change the mysql version. So I went home and configured it on my computer as follows:

Python-2.7.10.msi installation, and then add the installation path in path

Mysql-5.5.46-win32.msi: install, and then add the installation path in path, and then refer to the previous article "Install mysql under windows"

MySQL-python-1.2.3.win32-py2.7.exe: Install directly, and then import MySQLdb to see if the installation is correct

It's okay to test the python connection. It's speechless! (Of course, enter netstat-ano in cmd to check that the localadress of mysql port is This is normal)



Compile a py script file after installing the first three files. The content is as follows:

Import MySQLdb
Conn = MySQLdb. connect (
Host = 'localhost', # is also supported
Port = 3306,
User = 'root ',
Passwd = '000000 ',
Db = 'mysql ',
Cur = conn. cursor ()
Cur.exe cute ("select version ();")
Data = cur. fetchone ()
Print "Database version: % s" % data

F5 runs the script and outputs the Database version: 5.5.46. It seems that there is no problem at all.

Last provided (if the connection fails, please send a private message, thank you !) :

Python-2.7.10.msi: https://www.python.org/downloads/windows/

Mysql-5.5.46-win32.msi? Id = 458972

MySQL-python-1.2.3.win32-py2.7.exe: http://vdisk.weibo.com/s/awZ3drpB3YFxO

Related Article

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.