Today, the Python version on the company's computer is the same as the one on his home computer, unlike the MySQL company version 5.6, which took two days without the configuration of Python and MySQL.
Simply said Python connection MySQL has been reported 2003 error, the error code is: (2003, "Can ' t, connect to MySQL server on ' localhost ' (10061)"
Baidu on the internet for a day still did not find a solution, seemingly mysql5.6 up, its configuration changed, anyway, the company computer on the MySQL service startup, through the cmd input Netstat-ano view MySQL port use, the results found its localadress:: 1, Seems to be IPv6 address, to the present do not know how to solve.
Back home, think of online a senior said that really can't change a version of the MySQL bar, so home in their own computer configuration as follows:
Python-2.7.10.msi install, and then add the installation path in path
Mysql-5.5.46-win32.msi: Install, then add the installation path in path, then refer to the previous article, "Install MySQL under Windows"
Mysql-python-1.2.3.win32-py2.7.exe: Install directly, then import MYSQLDB is installed correctly
Test Python connection actually no problem, really no language! (Of course, with cmd input Netstat-ano view MySQL port localadress is 127.0.0.1, this is the normal situation)
Body:
After installing the previous three, write a py script file that reads as follows:
Import MySQLdb
Conn=mysqldb.connect (
host= ' localhost ', #127.0.0.1 can also
port=3306,
User= ' Root ',
Passwd= ' 123456 ',
db= ' MySQL ',
)
Cur=conn.cursor ()
Cur.execute ("Select VERSION ();")
data = Cur.fetchone ()
Print "Database version:%s"% data
F5 run the script, output database version:5.5.46, it seems absolutely no problem ah.
Finally, if the connection is invalid, please send a private messages, thank you! ):
python-2.7.10.msi:https://www.python.org/downloads/windows/
mysql-5.5.46-win32.msi:http://dev.mysql.com/downloads/file/?id=458972
Mysql-python-1.2.3.win32-py2.7.exe:http://vdisk.weibo.com/s/awz3drpb3yfxo
[Very depressed]python2.7 connection mysql5.5 configuration