Home  >  Article  >  Backend Development  >  Various problems and solutions encountered when python interacts with mysql

Various problems and solutions encountered when python interacts with mysql

不言
不言forward
2018-10-10 15:53:462331browse

The content of this article is about various problems and solutions encountered in the interaction between python and mysql. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Started to learn python to interact with MySQLdb, and encountered many pitfalls

The first one

%d format: a number is required, not str

Solution:

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

Just

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

mysql -u root -p enter the database

show variables like 'max_connect_errors';

View the maximum number of connections

set global max_connect_errors = 1000;

Modify the value of max_connect_errors:

(3) Check whether the modification is successful

> show variables like '%max_connect_errors%';

Solution 2: Use the mysqladmin flush-hosts command to clean up the hosts file

(1) Use the command to modify in the found directory: mysqladmin -u xxx -p flush-hosts

or

> flush hosts;

Solution 3: Restart mysqld

can also be used Before restarting, increase this parameter in the configuration file.

# vi /etc/my.cnf
max_connect_errors = 100

The above is the detailed content of Various problems and solutions encountered when python interacts with mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete