Python script to iterate through mysql tables and alter tablespace - python

I'm in the process of restoring a mysql database. I am trying to loop through the mysql tables and discard each table's tablespace so i can replace it with the old .ibd file. What is the proper Python code to use to accomplish the
ALTER TABLE <table> DISCARD TABLESPACE
for each table in the database using a Python script? I'm using Python 3 with mysql 8.0
Thanks
~brohjoe

The first you need for connect to a database is a thing named connector, on your case you need a connector for language python and version 8.0 of MySQL on this case you need download the connector from here: https://dev.mysql.com/downloads/connector/python/
For install a connector: https://dev.mysql.com/doc/connector-python/en/connector-python-installation-binary.html
When you have installed it, you can start to make connection to database and other things via this documentation references: https://dev.mysql.com/doc/connector-python/en/connector-python-examples.html

Related

Cassandra Python Driver Not Processing Queries (intermittently)

I'm having an issue where I'm connecting to a local Cassandra DB using Python Cassandra Driver. Issue is, there will intermittently be an issue where my CREATE TABLE queries are not being executed.
There is also an issue where I can see the table via DESC table in CQLSH, but upon execution of a SELECT query, it tells me that the table doesn't exist.
Restarting my virtual machine where my Cassandra is installed seems to fix this for awhile.
What is the cause of this and how do I fix it?

Copying records from one oracle database to another using python code

Could you please help me with the follwing request
I need to copy records from one oracle db ( production environment) to another ( test environment) using python code.
Oracle db version 11g
Could you help me out.
Check out odo blaze:
http://odo.pydata.org/en/latest/overview.html
It can handle data migration across many different data types and databases

why Python is required to install Cassandra

To install cassandra DB, python is required. Why is that so.?
What role Python plays in cassandra during installation and after(Is it for Driver connections?, or for cqlsh? because I see some python related files in cqlshlib folder)?
Cassandra is also a DB like others mongodb or mysql, oracle(of course some these are not noSQL and not distributed).
Because the cqlsh is written in Python...

Querying a MySQL database with Python without installing MySQL

I'd like to query a MySQL database using Python, but evidently the MySQLdb package requires a huge toolchain of MySQL stuff to be separately installed.
How can I query a MySQL database using a Python script without installing a bunch of unnecessary MySQL stuff, including conferring MySQL server capability on the client machine?
I don't love Perl, but it appears that the DBI package allows a Perl script to interface with MySQL without any MySQL stuff external to the package. I'm looking for something similar for Python.
You need to find a pure mysql python library. I have seen a couple over the last couple months. A quick google search yoelded pymysql. It has a large following on github. It looks promising. Pymysql is a pure python mysql client.
https://github.com/petehunt/PyMySQL
MySQLdb is just one of the available database drivers. It requires all that extra installation stuff, because it compiles c extensions and is one of the faster options.
There are a handful of other database drivers, some of which are pure-python.
The SqlAlchemy project has one of the more up-to-date collections of database drivers:
http://docs.sqlalchemy.org/en/latest/core/engines.html
PyMysql is a pure python driver, so it won't need to be built against the local MySql library.

Best way to access Firebird DB from a remote desktop.

I have a Firebird DB set up on my computer and I want to be able to retrieve data from a different computer. What is the best way to go about this?
I am running windows and using python.
Install firebird client to the client pc
To connect firebird programmaticaly from python you should install a python Firebird driver.
For Python 2.x, you can use kinterbasdb. This is the legacy driver and I think it is not actively developed but only maintained.
To connect windows based server database from kinterbasdb you can use
Import kinterbasdb as k
k.init(type_conv = 300) #
con = k.connect(dsn='127.0.0.1:c:\\db\\test.fdb', user='sysdba', password='masterkey', charset='YOUR_CHARSET', dialect=3)
Of course you should adjust connection parameters according to your system. Kinterbasdb documentation is here
If you want use an ORM, you can use SqlAlchemy which uses kinterbasdb for Firebird Support
For Python 3k you can use pyfirebirdsql which also supports Python 2.5+ and under active development, but not supported by SqlAlchemy yet.
Run Firebird server on the computer with database file and connect to it from remote computer. You will need in Firebird client library installed on remote computer.
I think we need a bit more info.
Do you want database access - as in "I want to be able to edit table layout and define new tables, views, procedures and so on" ?
Or do you only need to get data from the database using python ?
The latter could be achieved by installing a Firebird client (in essence its a dll (fbclient.dll)) and then use a connect string from python to connect to your database.

Categories