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?
Daniel Roseman
602k68 gold badges911 silver badges924 bronze badges
1 Answer 1
You have to import the pooling by using this line of code.
import mysql.connector.pooling
answered Jun 14, 2020 at 23:40
Jonathan Gagne
4,4095 gold badges20 silver badges31 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
import mysql.connector.pooling, or just part of that?import mysql.connectorimport mysql.connector.poolingit works. Thanks @Alex Hall