简体   繁体   中英

Python mysql.connector AttributeError

I am using Python 3.6 and mysql-connector 2.1.6 on macOS High Sierra. Following the instructions in the example on this documentation page ' https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnectionpool-constructor.html ', when I attempt to create a connection pool as follows:

cnxpool = mysql.connector.pooling.MySQLConnectionPool(pool_name = "mypool",pool_size = 3,**dbconfig)

I get the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2869, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-b07112a83246>", line 1, in <module>
    cnxpool = mysql.connector.pooling.MySQLConnectionPool(pool_name = "mypool",pool_size = 3,\**dbconfig)
AttributeError: module 'mysql.connector' has no attribute 'pooling'**

I have provided a valid **dbconfig argument.

May someone please help explain why it's not working?

您必须使用这行代码导入池。
import mysql.connector.pooling

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM