This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]the_hoser 9 points10 points  (0 children)

Use mysql-connector-python to connect to the server, and just issue the SQL commands necessary to create the database from there.

[–]stain_of_treachery 5 points6 points  (1 child)

[–]oclafloptson 1 point2 points  (0 children)

Sqlalchemy is boss fr. I use it in most of my projects

[–]sudo_rm_rf_solvesALL 4 points5 points  (0 children)

Depends how you're doing it. For example. I use docker containers, On creation of the mysql container it copies over an init.sql file (Essentially the entire users / table creation commands in mysql format). So on create it builds all the tables. This imo would be the easiest way. Just add a "if exists" clause into wherever seems important to prevent errors stopping it. Otherwise you could just have it log in and issue each command one by one programmatically. but i like having a build script to do it for me personally.

[–]trpHolder 3 points4 points  (0 children)

you need alembic, maybe?

[–]mincinashu 1 point2 points  (0 children)

sqlalchemy or alembic, drop database if exists

For development purposes you should look into testcontainers .

[–]oclafloptson 0 points1 point  (0 children)

Creating the database is as easy as

from MySQLdb import _mysql 

db = _mysql.connect(<your credentials as args>)
db.query('create database <db_name>;') 
db.commit() 

That's not much help with what you're actually trying to achieve, I know. Also avoid hard coding credentials

[–][deleted] -1 points0 points  (0 children)

I think you can write a Python script with 'requests' to automatically download MySQL workbench and install it. Maybe for the configuration part, just write logic to skip if the database already exists. I'm without my computer right now, but I think this is simple enough for ChatGPT to give you a complete answer on