python连接mysql数据库出错,已经尝试了网上的几种解决方法
http://blog.csdn.net/lishan9133/article/details/7024989之前是按照上面的教程安装了mysqldb模块,可是在实际操作...
http://blog.csdn.net/lishan9133/article/details/7024989
之前是按照上面的教程安装了mysqldb模块,可是在实际操作过程中,找不到对应行的代码,所以并没有按照上面的改。
打开数据库连接
db = MySQLdb.connect(
host='192.188.80.41',
port=3306,
user='root',
passwd='123456',
db='db_zhuanjia',
charset='utf8')
使用cursor()方法获取操作游标
cursor = db.cursor()
SQL 插入语句
sql = """ INSERT INTO EMPLOYEE(Sex)
VALUES (ans2(1))"""
try:
# 执行sql语句
cursor.execute(sql)
# 提交到数据库执行
db.commit()
except:
# Rollback in case there is any error
db.rollback()
关闭数据库连接
db.close()
报错代码:
Traceback (most recent call last):
File "G:\python\1\craweler2.py", line 44, in
charset='utf8')
File "G:\python\1\lib\site-packages\MySQLdb__init__.py", line 80, in Connect
return Connection(*args, **kwargs)
File "G:\python\1\lib\site-packages\MySQLdb\connections.py", line 187, in init
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2003, "Can't connect to MySQL server on '192.188.80.41' (10060)") 展开
之前是按照上面的教程安装了mysqldb模块,可是在实际操作过程中,找不到对应行的代码,所以并没有按照上面的改。
打开数据库连接
db = MySQLdb.connect(
host='192.188.80.41',
port=3306,
user='root',
passwd='123456',
db='db_zhuanjia',
charset='utf8')
使用cursor()方法获取操作游标
cursor = db.cursor()
SQL 插入语句
sql = """ INSERT INTO EMPLOYEE(Sex)
VALUES (ans2(1))"""
try:
# 执行sql语句
cursor.execute(sql)
# 提交到数据库执行
db.commit()
except:
# Rollback in case there is any error
db.rollback()
关闭数据库连接
db.close()
报错代码:
Traceback (most recent call last):
File "G:\python\1\craweler2.py", line 44, in
charset='utf8')
File "G:\python\1\lib\site-packages\MySQLdb__init__.py", line 80, in Connect
return Connection(*args, **kwargs)
File "G:\python\1\lib\site-packages\MySQLdb\connections.py", line 187, in init
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2003, "Can't connect to MySQL server on '192.188.80.41' (10060)") 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询