Debug for mysql connection with python mysql.connector

Debug code used when flask connection is not broken

What if it wasn't a flask? Used to confirm

Keep it as a record for the time being


import mysql.connector

from mysql.connector import Error
from mysql.connector.connection import MySQLConnection
from mysql.connector import pooling
try:
# alias mysqld="mysql -h db.com -P3306 -udev  -p "
    connection_pool = mysql.connector.pooling.MySQLConnectionPool(pool_name="pynative_pool",
                                                                  pool_size=5,
                                                                  pool_reset_session=True,
                                                                  host='db.com',
                                                                  port=3306,
                                                                  database='db',
                                                                  user='dev',
                                                                  password='****')

    print ("Printing connection pool properties ")
    print("Connection Pool Name - ", connection_pool.pool_name)
    print("Connection Pool Size - ", connection_pool.pool_size)

    # Get connection object from a pool
    connection_object = connection_pool.get_connection()


    if connection_object.is_connected():
       db_Info = connection_object.get_server_info()
       print("Connected to MySQL database using connection pool ... MySQL Server version on ",db_Info)

       cursor = connection_object.cursor()
       cursor.execute("select database();")
       record = cursor.fetchone()
       print ("Your connected to - ", record)

except Error as e :
    print ("Error while connecting to MySQL using Connection pool ", e)
finally:
    #closing database connection.
    if(connection_object.is_connected()):
        cursor.close()
        connection_object.close()
        print("MySQL connection is closed")

Recommended Posts

Debug for mysql connection with python mysql.connector
Connection pooling with Python + MySQL
INSERT into MySQL with Python [For beginners]
[Introduction for beginners] Working with MySQL in Python
Debug Python with VS Code
Debug with PEPPER python interpreter
UDP simultaneous connection with Python
Build Mysql + Python environment with docker
Debug python multiprocess program with VSCode
Getting Started with Python for PHPer-Classes
I want to debug with Python
Getting Started with Python for PHPer-Functions
I made a lot of files for RDP connection with Python
Easy keyword extraction with TermExtract for Python
Receive textual data from mysql with python
WEB scraping with Python (for personal notes)
Manually ssh registration for coreserver with python
Use DeepL with python (for dissertation translation)
Amplify images for machine learning with python
Tips for dealing with binaries in Python
Connect to MySQL with Python within Docker
Tips for using python + caffe with TSUBAME
[Shakyo] Encounter with Python for machine learning
Process multiple lists with for in Python
Connect with mysql.connector with ssh tunnel in Python 3.7
Getting Started with Python for PHPer-Super Basics
[Python] Read images with OpenCV (for beginners)
Let's do MySQL data manipulation with Python
WebApi creation with Python (CRUD creation) For beginners
Preparation for scraping with python [Chocolate flavor]
[For beginners] Try web scraping with Python
python [for myself]
FizzBuzz with Python3
Scraping with Python
Statistics with python
ODBC connection to FileMaker 11 Server Advanced with Python 3
Get a ticket for a theme park with python
Scraping with Python
[Translation] Getting Started with Rust for Python Programmers
Create a LINE BOT with Minette for Python
Play with Lambda layer (python) for about 5 minutes
Use logger with Python for the time being
Twilio with Python
Procedure for creating a LineBot made with Python
Integrate with Python
Debug with VS Code using boost python numpy
Wrap C with Cython for use from Python
Move THORLABS automatic stage with Python [for research]
Play with 2016-Python
AES256 with python
~ Tips for Python beginners from Pythonista with love ① ~
python starts with ()
[Python] Collect images with Icrawler for machine learning [1000 images]
Image Processing with Python Environment Setup for Windows
Note for formatting numbers with python format function
Commands for creating a python3 environment with virtualenv
Bingo with python
Zundokokiyoshi with python
Wrap C ++ with Cython for use from Python
Memo for editing scenes with Blender python (W.I.P.)
~ Tips for Python beginners from Pythonista with love ② ~