Access mysql-py shell commands from within Python - python

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.

Related

Remotely accessing sqlite3 in Django using a python script

I have a Django application that runs on apache server and uses Sqlite3 db. I want to access this database remotely using a python script that first ssh to the machine and then access the database.
After a lot of search I understand that we cannot access sqlite db remotely. I don't want to download the db folder using ftp and perform the function, instead I want to access it remotely.
What could be the other possible ways to do this? I don't want to change the database, but am looking for alternate ways to achieve the connection.
Leaving aside the question of whether it is sensible to run a production Django installation against sqlite (it really isn't), you seem to have forgotten that, well, you are actually running Django. That means that Django can be the main interface to your data; and therefore you should write code in Django that enables this.
Luckily, there exists the Django REST Framework that allows you to simply expose your data via HTTP interfaces like GET and POST. That would be a much better solution than accessing it via ssh.
Sqlite needs to access the provided file. So this is more of a filesystem question rather than a python one. You have to find a way for sqlite and python to access the remote directory, be it sftp, sshfs, ftp or whatever. It entirely depends on your remote and local OS. Preferably mount the remote subdirectory on your local filesystem.
You would not need to make a copy of it although if the file is large you might want to consider that option too.

Python consumer application with database

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.

Build postgreSQL in Windows with Python

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.

Understanding SQLite conceptually

I looked at the sqlite.org docs, but I am new to this, so bear with me. (I have a tiny bit of experience with MySQL, and I think using it would be an overkill for what I am trying to do with my application.)
From what I understand I can initially create an SQLite db file locally on my MAC and add entrees to it using a Firefox extension. I could then store any number of tables and images (as binary). Once my site that uses this db is live, I could upload the db file to any web hosting service to any directory. In my site I could have a form that collects data and sends a request to write that data to the db file. Then, I could have an iOS app that connects to the db and reads the data. Did I get this right?
Would I be able to run a Python script that writes to SQLite? What questions should I ask a potential hosting service? (I want to leave MediaTemple, so I am looking around...)
I don't want to be limited to a Windows server, I am assuming SQLite would run on Unix? Or, does it depend on a hosting service? Thanks!
I could upload the db file to any web hosting service to any directory
Supposing that the service has the libraries installed to handle sqlite, and that sqlite is installed.
Would I be able to run a Python script that writes to SQLite
Yes, well, maybe. As of Python 2.5, Python includes sqlite support as part of it's standard library.
What questions should I ask a potential hosting service
Usually, in their technical specs they will list what databases/libraries/languages are supported. I have successfully ran Python sites w/ sqlite databases on Dreamhost.
SQLite would run on Unix
Most *nix flavors have pre-packaged sqlite installation binaries. The hosting provider should be able to tell you this as well.

Uploading a mysql database to a webserver supporting python

I have a written a very small web-based survey using cgi with python(This is my first web app. ).The questions are extracted from a MySQL database table and the results are supposed to be saved in the same database. I have created the database along with its table locally. My app works fine on my local computer(localhost). To create db,table and other transaction with the MySQL i had to do import MySQLdb in my code.
Now I want to upload everything on my personal hosting. As far as I know my hosting supports Python,CGI and has MySQL database. And I know that I have to change some parameters in the connection string in my code, so I can connect to the database, but I have two problems:
I remember that I installed MySQLdb as an extra to my Python, and in my code i am using it, how would I know that my hosting's python interpretor has this installed, or do I even need it, do I have to use another library?
How do I upload my database onto my hosting?
Thanks
If you have shell access, you can fire up the python interpreter by running python and type import MySQLdb at the >>> prompt. If you get no errors in return, then its installed.
Likewise, if you have shell access, this page will help you with importing and exporting using the mysql command. I found it by googleing "import export mysql".
You can write a simple script like
import MySQLdb and catch any errors
to see if the required package is
installed. If this fails you can ask
the hosting provider to install your
package, typically via a ticket
The hosting providers typically also provide URL's to connect to the MySQL tables they provision for you, and some tools like phpmyadmin to load database dumps into the hosted MySQL instance
To check if MySQLdb library is installed on your hosting, simply open a python shell and type: import MySQLdb. If everthing goes ok, you're readt to go. If you get: ImportError: No module named MySQLdb, that means the the library is not installed and you nedd to install it.
You need that library or some library that provides similar support, because Python does not support native access to MySQL databases.
To transfer you database to your hosting check mysqldump.

Categories