Various problems and solutions encountered when python interacts with mysql

不言
Release: 2018-10-10 15:53:46
forward
2334 people have browsed it

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
Copy after login

Just

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

mysql -u root -p enter the database

show variables like 'max_connect_errors';
Copy after login

View the maximum number of connections

set global max_connect_errors = 1000;
Copy after login

Modify the value of max_connect_errors:

(3) Check whether the modification is successful

> show variables like '%max_connect_errors%';
Copy after login

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;
Copy after login

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
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!