Python Connection MySQL Error summary

Source: Internet
Author: User
Tags bind

Error One:

The code is as follows Copy Code

File "/usr/lib/pymodules/python2.6/mysqldb/__init__.py", line Bayi, in Connect
Return Connection (*args, **kwargs)
File "/usr/lib/pymodules/python2.6/mysqldb/connections.py", line 170, in __init__
Super (Connection, self). __init__ (*args, **KWARGS2)
_mysql_exceptions. Operationalerror: (2003, "Can" T connect to the MySQL server on ' xxx.xxx.xxx.xxx ' (111) ")

Workaround:

1, edit my.cnf, default is/etc/mydql/my.cnf, comment out bind-address = 127.0.0.1 or modify to 0.0.0.0;

The code is as follows Copy Code

# Instead of skip-networking The default is now to listen only
# localhost which are more compatible and are not less secure.
# bind-address = 127.0.0.12, restart MySQL:

Sudo/etc/init.d/mysql restart

Error Two:

The code is as follows Copy Code

File "/usr/lib/pymodules/python2.6/mysqldb/__init__.py", line Bayi, in Connect
Return Connection (*args, **kwargs)
File "/usr/lib/pymodules/python2.6/mysqldb/connections.py", line 170, in __init__
Super (Connection, self). __init__ (*args, **KWARGS2)
_mysql_exceptions. Operationalerror: (1130, "Host ' xxx.xxx.xxx.xxx ' isn't allowed to connect to this MySQL server")

Workaround:

The code is as follows Copy Code

Mysql> GRANT all privileges in *.* to ' root ' @ '% ' identified under ' root ' with GRANT OPTION; This statement means: Allow all the root user and enter the root password of the host Log in to the MySQL Server.

The username and password are replaced with the required, if the '% ' is replaced by the corresponding host name, then only the host can log in.

Error Three:

The code is as follows Copy Code

(1040, ' Too many connections ')
The reason is: ' Nonetype ' object has no attribute ' cursor ' web crawler to multiple threads, the connection database has the above error.

Workaround One:

The code is as follows Copy Code

Edit my.cnf, default is/etc/mydql/my.cnf, modify Max_connections value is 10000, the default is 100, the actual MySQL server allows the maximum number of connections 16384.

Workaround Two:

Use a database connection pool.

Workaround Three:

Before the program structure to crawl to a data that produces an SQL statement that inserts a data, modify the program structure to put the process threads generated SQL statements into the queue, with a separate process to get out of SQL Insert database.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.