Python mysql.connector AttributeError

时间:2018-04-15 11:24:50

标签: python mysql

我在macOS High Sierra上使用Python 3.6和mysql-connector 2.1.6。按照本文档页面“https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnectionpool-constructor.html”中示例中的说明操作,当我尝试按如下方式创建连接池时:

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

我收到以下错误:

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

我提供了一个有效的** dbconfig参数。

请有人帮忙解释一下它为什么不起作用?

1 个答案:

答案 0 :(得分:1)

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