python与mysql交互会遇到的各种问题及解决方法


本文摘自php中文网,作者不言,侵删。

本篇文章给大家带来的内容是关于python与mysql交互会遇到的各种问题及解决方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

开始学python 交互MySQLdb,踩了很多坑

第一个

%d format: a number is required, not str

解决方法:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

# -*- coding: utf-8 -*-

import MySQLdb

try:

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 count

conn.commit()

csl.close()

conn.close()

except Exception,e:

print e.message

an integer is required (got type str)

port=3306

即可

1

(1129, "Host '192.168.65.1' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'")

mysql -u root -p 进入数据库

1

show variables like 'max_connect_errors';

查看最大连接数

1

set global max_connect_errors = 1000;

修改max_connect_errors的值:

(3)查看是否修改成功

1

> show variables like '%max_connect_errors%';

解决方法2:使用mysqladmin flush-hosts 命令清理一下hosts文件

(1)在查找到的目录下使用命令修改:mysqladmin -u xxx -p flush-hosts

或者

1

> flush hosts;

解决方法3:重启mysqld

也可以在重启之前,在配置文件中将该参数调大。

1

2

# vi /etc/my.cnf

max_connect_errors = 100

以上就是python与mysql交互会遇到的各种问题及解决方法的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python ide修改背景颜色的教程

vs可以写Python

Python怎么利用gpu加速

Python如何修改dataframe列名

Python中index的用法是什么

Python如何输出换行

有关eclipse 乱码问题的几点讲解

Python基础学完后再学什么

Python关于tkinter模块中类的三种继承方式示例分享

Python中idle是什么

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...