Python Forum

Full Version: Python3 mysql connection performance
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Quote:Hello,
I would like to know what allows me to get the best performance when connecting from Python to mysql server:

1. Create a connection in each of the files

2. Create a file containing the database connection and cursors and then import it from each of the files.

Regards!
I think that pandas is amazingly fast when dealing with PostGreSQL and sqlite3 so would expect the same with MySQL
There are a lot of tutorials available.
Here's a quick couple of script that both create and read an MySQL table.
https://pythontic.com/pandas/serialization/mysql
to find more, google: 'use pandas to work with MySQL databases'
Could you perhaps show a code sample? I'm reading more of a design question than a performance one, but it'd be useful to see what your code looks like before making suggestions.
see: LoadDatabase.py here: https://python-forum.io/thread-33843.html
This is the method that I use.
This entire tutorials is about automatically creating a database directly from csv files and uses pandas to load the database.
Requires model which is also created within the tutorial by: BuildDbModel.py
(Feb-19-2022, 01:19 PM)Larz60+ Wrote: [ -> ]see: LoadDatabase.py here: https://python-forum.io/thread-33843.html
This is the method that I use.
This entire tutorials is about automatically creating a database directly from csv files and uses pandas to load the database.
Requires model which is also created within the tutorial by: BuildDbModel.py

Quote:Thanks Larz60 for your attention and your time!!
(Feb-19-2022, 06:21 AM)ndc85430 Wrote: [ -> ]Could you perhaps show a code sample? I'm reading more of a design question than a performance one, but it'd be useful to see what your code looks like before making suggestions.

Quote:Actually I do this in every single .py file:

import mysql.connector
mydb = mysql.connector.connect(
   host="SERVER IP"
   port="SERVER PORT"
   user="USER"
   password="PASSWORD"
   database="DB"
   )