MySQL -- What language to use for DBA automation? (Perl, Python...?) - mysql

I've inherited an existing MySQL (5.x) instance and there's been little to no maintenance of the system
My question as a MSSQL DBA is -- What tools are most commonly used to automate administrative tasks when scripting/automation MySQL tasks?
For my MSSQL servers I mainly use native T-SQL, PowerShell or C# to create my automation processes. T-SQL and Powershell are the most common as they are 'native' to the system and do not create dependencies by having to maintain additional software; C# brings .NET version dependencies (sortof)....
I see that Python is quite popular as well as Perl, however my Perl knowledge is 'nil and Python looks fairly easy for what my requirements are. Are there any good reasons to use one or another language for writing automation scripts/processes?

Before scripting anything against mysql, you should leverage the mysql client utilities. That way, you do not find yourself reinventing the wheel.
As long as you have a good mastery over the mysql client utilities, whichever langauge you decide to program in for custom utilities is simply a matter of personal choice.
IMHO from a DBA perspective, it is best to perform basic shell scripting to call SQL scripts. Again, just a matter of personal choice.

Generally, whatever you're familiar with. Our shop works in PHP, so our MySQL automation scripts are in PHP as well.

Related

Can I connect to SQL with Node.JS without an external package, or with one universal package?

I know it may be reinventing the wheel to some extent, but I'm creating a package of my own in Node.JS where I would like to keep dependencies to an absolute minimum. This program should connect to SQL (at first, just MySQL, but eventually several different flavors, so if the same answer applies to PostgreSQL, MSSQL, etc. a note about that would be much appreciated) and be able to run queries and such. Is there a way to do so through Node without using an external package like mysql or mssql?
I do understand that this sounds very impractical, and so I see the need to use "fully debugged open-source software" as the commenter put it. However, requiring a new package for every SQL flavor I extend my program to would be impractical as well. If I must install a package, is there some sort of universal one that I can use for Node.JS (something like PDO in PHP)? If so, what is the basic way of connecting to, say, MySQL?
Thanks in advance.
Node has RDBMS-specific packages like mysql, pg, sqlite3, mssql, ibm_db, oracledb, ... all the same except where they aren't.
The php world boasts a couple of database abstraction layers that can talk to multiple makes and models of RDBMS. For Java, JDBC serves the same purpose.
The npm ladc package is a similar project for nodejs; it uses the existing packages for connecting to databases. It seems to be in an early version and not heavily used, according to its npm page.
Sequelize is an object-relational database abstraction above some RDBMSs. If you are able to use an object-relational model for your data, it's probably a good choice. If you're using lots of pure SQL, ladc might make sense.
It seems as if you're blazing a trail with your project.

Sample datasets for practice - Oracle pl/sql

I am a new user of SQL, I use Oracle pl/sql as a Programming software. I have done an introductory course to SQL that included some datasets. However I'd like to continue practicing, some real life problems that include requests of querying very simple statements to difficult ones that include indexes, etc.
Does anyone have any links/sites where I can further pursue SQL training for free? I've done a Stakexchange and Google search with not much luck.
As you probably know, Oracle ussually comes with some sample schemas like HR, SH... listed here
Also, you can install HammerOra benchmarking tool. It's commonly used to test TPC-C and TPC-H on different RDBMS. It will install some schemas on your DB with variable size.
You can also install some virtual appliances.
There are more there, but I think the coolest is StackOverflow DB, too bad is MSSQL.

Do I need to know SQL to learn 4D database?

i was offered a task in relation to 4D database, however, I do not have any database skill such as SQL, I can program but not in database aspect, just wondering should I learn some SQL before 4D database? Or are they totally different? Thanks for suggestion.
4D is much more than just a database; it includes a GUI designer, has it's own programming language and includes a compiler for building double-clickable applications. There are many plugins extending the product and a plugin SDK that allows you to write c++ code to extend it yourself. The possibilities of 4D are pretty limitless. The main point here is that you could create an application that does not even use the database engine therefore database background would not be so important.
You don't need to know SQL to program in 4D. There is a sql layer but you can also use the non-SQL commands to achieve most of the same tasks. Granted that SQL may be better suited for some tasks, and the only option for others (see replication and synchronization). In general you should learn SQL as it will help in many different languages but don't let not knowing SQL stop you from using or learning 4D.
The 4D programming language has extensive documentation on doc.4d.com:
The 4D Language Reference contains the core commands
The 4D SQL reference covers the SQL aspect of the language.
The 4D Design Reference covers aspects of the design environment.
There is also a short crash course section on wikipedia that may be helpful to give you a glimpse of the language

how do you ensure database Interoperability

I'm starting a new opensource project (for real estate) and wanted to focus on using MySQL, but would also like to ensure it works in PostgreSQL. What is the best way to doing this without having to continually test in both environments? I'm assuming the db schema is close to the same, but there could be some differences on the SQL script to set up the databases - right? what about scripts?
What Development environment are you using?
if your using .NET, JAVA you could use an ORM(Object Relational Mapper) like Hibernate (NHibernate for .net) and that will take care of you db interoperability, for PHP or ruby I would look for something equivalent.
Edit point:
After looking at your profile it looks like your a python developer so you may find this link helpful what are some good python orm solutions posed on SOF 10 months ago
Seems to me that the only way to make absolutely sure is to target them both in your testing. I'm sure both DB's have development paths that may diverge, and you'll often find yourself faced with the prospect of using some MySQL-specific feature.
It's a PITA but the longer you go between tests against both the better the chance you'll have fireworks when you do.

mysql dump outside the command line

Do any of the modern programming languages support mysqldump as a method, Or is it still the domain of command line environments.
If you're using PHP and don't mind using a GPL license, then phpMyAdmin contains some code for MySQL dump (as well as to other formats like CSV, etc).
Check out the file:
libraries/export/sql.php
There are APIs available (database drivers) for .NET, Delphi, and generic ODBC/DAO, as well as libraries for C/C++ and other languages. It's never going to be written directly into a mainstream language itself; that would restrict the language from being as general purpose and therefore make it less useful.
Delphi, for instance, has a database framework called DBExpress; there's a DBExpress driver included out of the box for MS SQL Server, Oracle, MySQL, DB2, and others; what drivers are available depend on the version (Professional, Enterprise, or Architect) you decide to buy. MySQL is available in all versions.
Using the DBExpress framework makes Delphi usable with any database engine that someone decides to provide a DBExpress driver for, and the drivers can be written in Delphi itself. That keeps Delphi more general purpose; it's not hard-coded to work with only a single RDBMS.
EDIT: As others have said (I think Jarret), the source to mysqldump is available. Using the wrappers available for your language of choice, you should be able to implement the same functionality based on that source.
Your instinct is right... it would be pretty tough for a programming language library to provide API access to mysqldump. The source to mysqldump is written in C, with its own main() function; it's designed to operate pretty much as its own program. It gets built as an executable, and much of the error reporting and output are handled using direct print statements to stdout, and not using return values that could be wrapped into a language-specific value.
When most bindings for a specific programming language are compiled (PHP, python, Delphi, .NET, etc), they link against libmysql, and libmysql contains no reference to the mysqldump program. I can't say for sure that no one has written a wrapper, but it would be a very bizarre wrapper indeed.
In other words, your best bet is to use a sub-process from your programming language of choice to call the mysqldump tool, and absorb the results either from stdin or from a temp file.
Your question is rather vague. Please describe what you want to accomplish, and what you have tried already.
That being said, if you want to produce a DB dump of a MySQL database in the way that mysqldump does, I know of no API that makes it possible directly. But there are numerous other ways of dumping / backing up a DB, and the mysqldump format has its share of problems (not well defined for one thing, hence not easy to parse). So you might consider an alternative approach.