Python Forum
Python3 mysql connection performance
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python3 mysql connection performance
#1
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!
Reply
#2
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'
Reply
#3
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.
Reply
#4
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
Reply
#5
(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!!
Reply
#6
(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"
   )
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020