本篇文章给大家带来的内容是关于python与mysql交互会遇到的各种问题及解决方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
开始学python 交互MySQLdb,踩了很多坑
第一个
%d format: a number is required, not str
解决方法:
立即学习“Python免费学习笔记(深入)”;
# -*- coding: utf-8 -*-import MySQLdbtry:conn=MySQLdb.connect(host='localhost',port='3306',db='test',user='root',passwd='toor',charset='utf-8')csl=conn.cursor()count=csl.execute("inser into stu(stu_id,stu_name,stu_phone,stu_hometown) values('0003','kj','19564832601',河北)")print countconn.commit()csl.close()conn.close()except Exception,e:print e.messagean integer is required (got type str)port=3306
登录后复制
即可
(1129, "Host '192.168.65.1' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'")
登录后复制
mysql -u root -p 进入数据库
show variables like 'max_connect_errors';
登录后复制
查看最大连接数
set global max_connect_errors = 1000;
登录后复制
修改max_connect_errors的值:
(3)查看是否修改成功
> show variables like '%max_connect_errors%';
登录后复制
解决方法2:使用mysqladmin flush-hosts 命令清理一下hosts文件
(1)在查找到的目录下使用命令修改:mysqladmin -u xxx -p flush-hosts
或者
> flush hosts;
登录后复制
解决方法3:重启mysqld
也可以在重启之前,在配置文件中将该参数调大。
# vi /etc/my.cnfmax_connect_errors = 100
登录后复制
以上就是python与mysql交互会遇到的各种问题及解决方法的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2260660.html