python與mysql互動中的各種坑

kailicard發表於2018-10-09

開始學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

相關文章