<span style="font-size:18px;"># encoding: utf-8#!/usr/bin/pythonimport MySQLdb# 打开数据库连接db = MySQLdb.connect("localhost","root","123456","test" )</span>
显示错误:
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
错误原因:
原来错误出现在localhost这个名称的解析上。
修改方法:修改为iP,若为本地测试,修改为127.0.0.1;若为服务器:修改为IP。
# encoding: utf-8#!/usr/bin/pythonimport MySQLdb# 打开数据库连接db = MySQLdb.connect("127.0.0.1","root","123456","test" )