码迷,mamicode.com
首页 > 数据库 > 详细

python与mysql交互中的各种坑

时间:2018-10-10 01:02:29      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:查找   xxx   sdn   cal   配置文件   blog   参数   解决   block   

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

第一个

%d format: a number is required, not str

参照以下博客:

https://blog.csdn.net/u011878172/article/details/72599120

# -*- 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即可

(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.cnf

max_connect_errors = 100

python与mysql交互中的各种坑

标签:查找   xxx   sdn   cal   配置文件   blog   参数   解决   block   

原文地址:https://www.cnblogs.com/kk328/p/9763926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!