时间:2021-07-01 10:21:17 帮助过:12人阅读
http://blog.csdn.net/lishan9133/article/details/7024989 之前是按照上面的教程安装了mysqldb模块,可是在实际操作过程中,找不到对应行的代码,所以并没有按照上面的改。 打开数据库连接 db = MySQLdb.connect( host='192.188.80.41', port=3306, user='r
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 = db.cursor()
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)")