I want to implement a simple application (for Windows), mainly for data collection and I should be able to run some queries.
I can produce an exe file from the python code, but I don't want to install the database separately, rather I'd include it in an installer. I think some other applications do the same or they require MySQL to be installed -- not in development mode -- since I saw in Windows' Programs and Features that there are some MySQL installations.
So my question is: Is there a way to use MySQL or a specific preparation method of an application so I am able to use some database operations inclusive saving data? Remark: any database would work, I was referring to MySQL because I suspect I saw some examples.
You could use Pyinstaller to make an exe out of your database and Python file. Python natively supports sqlite so you don't have to install anything extra if you use that.
Related
I've never worked with sql/mysql but I've read a bunch of tutorials.
I want to be able to create databases with Python and then conveniently access it using mysql terminal tools.
In Mysql there are relational tables that can be handled by mysql terminal application. In order to access this from python I was able to use python connector.
There are also document store aka nosql databases. To work with this I used mysql-py shell (Chapter 20 of mysql 8.0 manual). However, I cannot access it from within the python, as I didn't find an appropriate module. I understand that there are a bunch of databases created for python, like mongo, but I want to use the original mysql tools.
Is there one? I work on MAC OS.
Thanks,
Mikhail
I found out the answer : X Dev API.
So I've been looking all over the internet and only found resources/tutorials on how to connect to a MySQL server but my question is, how do you host a MySQL server both on Windows & Linux?
I am not quite sure what you are asking but if the question is how to run a database for python independent of the OS, consider using sqlite.
From the link (emphasis mine)
SQLite is an embedded SQL database engine. Unlike most other SQL
databases, SQLite does not have a separate server process. SQLite
reads and writes directly to ordinary disk files. A complete SQL
database with multiple tables, indices, triggers, and views, is
contained in a single disk file. The database file format is
cross-platform - you can freely copy a database between 32-bit and
64-bit systems or between big-endian and little-endian architectures.
These features make SQLite a popular choice as an Application File
Format. Think of SQLite not as a replacement for Oracle but as a
replacement for fopen().
So it allows you to use a database from your python code without the hassle of running a server or setting something up locally.
Note that sqlite can also be stored in-memory if you want to avoid writing to disk.
Unless you have a very specific reason to start the server from Python, I.e. you want to be able to programmatically do stuff you wouldn't do from the command line, I think the best you could do is to install an instance of Mysql server in your local machine, run it and then, you'll be able to connect to it from Python.
Bear in mind that your local installation of Mysql will be running on localhost (127.0.0.1)
I would like to make a Database editable with LibreOffice Base and usable with python. I can't find a way with the normal HSQLDB as it requires Java (I would as less as possible dependencies) and the same thing with SQLite3 as it requires the drivers for LibreOffice.
Be sure to use a split database setup, rather than the default embedded setup. Otherwise it will crash a lot.
One solution that does not require Java is to switch to a different DB engine, for example MySQL. With this setup, see How do I connect to a MySQL Database in Python? LibreOffice Base works well with MySQL.
See also https://wiki.openoffice.org/wiki/FAQ_(Base)#Do_I_need_Java_to_use_Base.3F. Split databases are discussed on that page as well.
I'm wondering if there is any built-in way in Python to test a MySQL server connection. I know I can use PyMySQL, MySQLdb, and a few others, but if the user does not already have these dependencies installed my script will not work? How can I write a Python script to test a MySQL connection without requiring external dependencies?
Python distributions do not include support for MySQL, which is only available by installing a third-party module such as PyMySQL or MySQLdb. The only relational support included in Python is for the SQLite database (in the shape of the sqlite3 module).
There is, however, nothing to stop you distributing a third-party module as a part of your application, thereby including the support your project requires. PyMySQL would probably be the best choice because, being pure Python, it will run on any platform and give you best portability.
Can i install and build postgreSQL from Source Code in Windows by using Python? Is it solid? Currently in their documentation they have Visual C++ as their only option!
And if it is possible (and reliable) where can i find prime material to use Python to build and customize my postgreSQL? I won't go and learn Visual C++ unless it is the only way. I also have GitBash if that helps...
For people who have no idea on db's. They never say that in documentations because they think it for granted.
IT ALL BOILS DOWN TO: It is another thing building_from_source/installing a db and a totally another thing interacting/working with a db.
There is library for accessing Postgres from python called psycopg. There is a tutorial on its use here.
To the extent that you are just learning about databases, you might also take a look at Sqlite, which is a more lightweight database and included in the python standard library
Since you want to use PostgreSQL you really don't need to compile anything. Simply install PostgreSQL and the windows binaries of psycopg2 (the PostgreSQL client library for python).
If you want to build the PostgreSQL database server - something you only want/need to do if you want to modify PostgreSQL itself, and which is something you probably don't want to do as a beginner - you should use whatever compiler the Postgres developers suggest since they most likely only have project/make files for that compiler.