1

I have created a CLI app in Python, a sort of library management system that uses a MySQL database to store records. If I wanted to release this as an installable app, could I do it without the end-user having to install MySQL on their own device, and going through the trouble of importing the database schema?

Note that the database is stored/hosted on the user's local machine and there is no web server interaction.

3
  • The only thing you need is the database driver, not the database itself. Commented Jan 18, 2024 at 14:44
  • @gargantuan You need to have MySQL installed on the local machine, or on the network it's connected to. If you didn't already know that you are short of sufficient understanding of your environment and shouldn't consider releasing your app at this point. Commented Jan 18, 2024 at 14:50
  • @TangentiallyPerpendicular I understood that, I was wondering if there is any way or alternative solution to deploy something like this. I'm a highschool student only learning MySQL/Python now, not really planning on releasing a production-ready app yet :) Commented Jan 18, 2024 at 15:07

1 Answer 1

1

This isn't possible using a DBMS like Mysql, Postgres, Mariadb. That is what SQLite is for. All you need for a SQLite database is to install the connector, form there the rest is handled.

Check out this example of database creation and querying.

import sqlite3

connection = sqlite3.connect("test")

cursor = connection.cursor()
cursor.execute("CREATE TABLE example (name TEXT, type TEXT, count INTEGER)")
cursor.execute("INSERT INTO example VALUES ('Sammy', 'shark', 1)")
rows = cursor.execute("SELECT * FROM example").fetchall()
print(rows)

You do not need to install the sqlite3 package with pip. As mentioned by a commenter, the package comes pre-installed with python.

Hope this helps!

Sign up to request clarification or add additional context in comments.

2 Comments

sqlite3 is an included package, no need for pip.
ah good call, hadn't realized ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.