Is it possible to export MySQL schema to XML? - mysql

With MySQL I can:
export data to XML
export data and/or schema to SQL
But I can't export table schema to XML. Is there some sort of pre-built mechanism or do I have to make that manually (iterating thru "show tables" and then parsing "show columns for tablexxx" ?
EDIT: No tools wanted, just mysql syntax (must dynamically run from my server code)

I don't know of a built-in feature for mysql to do this but you can look at phpmyadmin it can do the export to xml.

I didn't find such thing, so I assume no, it isn't. Feel free to correct me if I am wrong.

Related

MySQL structure to SQLite

I am trying to use MySQL workbench to export my model to SQLite. I don't need the data just the structure. Do you have any suggestion? Exporting to SQL and creating tables with SQLite3 using that won't work as there are several differences between MySQL and SQLite syntaxes.
From what I know there's no tool that can convert a MySQL SQL script to SQLite. You will probably have to manually rework the generated SQL. Or you could create a MySQL schema from your model and use one of the available tools to convert that schema. Needs a detour via an existing MySQL schema, however.

How to create a Mondrian schema (xx.mondrian.xml) for MySQL data base

I am going to customise Saiku analysis tool for my local MySQL data base. For that I have to change the their existing data source as following manner,
type=OLAP
name=steelwheels
driver=mondrian.olap4j.MondrianOlap4jDriver
location=jdbc:mondrian:Jdbc=jdbc:mysql://localhost/sampledata; \>Catalog=../webapps/saiku/steelwheels/steelwheels.mondrian.xml;JdbcDrivers=com.mysql.jdbc.Driver;
username=dbuser
password=password
According to above code, can any one please tell me how I generate Mondrian schema file called steelwheels.mondrian.xml with MySQL data base sampledata
Thanks
Download and open PSW or Pentaho Schema Workbench which can be found as part of the mondrian project on sourceforge.
This is going away with Mondrian4, but thats ages away at the moment.
If you are using Pentaho BI server then its really easy to create *.mondrian.xml file for your datasource using Pentaho User Console it will be easy to create and edit datasource and just use *.mondrian.xml file created under /biserver-ce/pentaho-solutions/admin/resources/metadata/.
I use that in my regular practice. It will be effective even if you dont use pentaho for your whole application but just use pentaho user console for this purpose.
At this moment my best solution is to use the data source wizard to create a new analysis, export it manually and edit it by hand in your favorite xml editor. (Example Notepad++ with XMLTools plugin).
Sadly it works better than using the old Pentaho Schema Workbench. You may try to create a DTD to validate the structure of XML against the schema. See the official documentation.
Maybe the Enterprise version has better tools to edit it.

How does the phpMyAdmin export feature work?

If I were to want to create a PHP function that does the same thing as the Export tab in phpMyAdmin, how could I do it? I don't know if there is a MySQL function that does this or if phpMyAdmin just builds the export file (in SQL that is) manually. Without shell access. Just using PHP.
I tried the documentation for mysqldump, but that seemed to require using the shell. I'm not quite sure what that even is -- maybe my question is: how do you use shell?
My silly idea is to allow non-technical users to build a site on one server (say a localhost) using MySQL then export the site, database and all, to another server (eg. a remote server).
I think I'm pretty clear on the Import process.
You can check the phpMyAdmin source code (an advantage of open-source software). Check the export.php script and the supporting functions in the libraries/export/sql.php script file.
In summary, what phpMyAdmin does is:
get a list of the tables in the given database (SHOW TABLES FROM...),
get the create query for each table (SHOW CREATE TABLE...),
parse it and extract column definitions from it,
get all data (SELECT * FROM...)
build a query according to column data.
I've written similar code for my own apps (for backup purposes, when the GPL license of phpMyAdmin doesn't allow me to use it), however I use DESCRIBE to get column definitions. I think they rather parse the SHOW CREATE TABLE output because contains more information than DESCRIBE output.
This way to generate SQL sentences requires a bit of care to handle the escaping but it allows for some flexibility, as you can convert types, filter or sanitize data, etc. It is also a lot slower than using a tool like mysqldump and you should take care of not consuming all available memory (write soon, write often, don't keep everything in memory).
If you will implement a migration process (from server to server) maybe it would be easier to do it with some shell scripting and calling mysqldump directly, unless you will do everything with PHP.

MySQL dump .sql script and import to an apache derby

So presumably mysqldump can export to ansi compatible format so that you can import to other vendors' databases.
However trying to import to an apache derby I face all this syntax errors.
Thought I try some regex and fix things but it seems that there are more than a couple.
Is there something I'm missing about mysqldump?
Tried ddlutils but couldn't make progress after step 3 with these docs which seem out of date.
Do I have any other options with that?
The mysqldump option --compatible=ansi doesn't produce a SQL script that is fully ANSI compatible, it just tries to produce a result that is more ANSI compatible: "Produce output that is more compatible with other database systems or with older MySQL servers."
Unfortunately, the SQL syntax supported by each database is a bit different. SQL is a relatively weak standard, much weaker than Javascript or even C. Some databases support compatibility features like MySQL does, or even compatibility modes (disclaimer: I'm the main author of H2), but even this is not enough sometimes.
You have multiple options: you could change the generated SQL script by hand, or you could use another tool to copy the table structure / data. One such tool is the SQuirreL DB Copy Plugin (I have never actually used it, but from what I heard it works well).
If you can export your data in CSV format, or something similar, then you can use the Derby data import procedures to import your data: http://db.apache.org/derby/docs/10.7/ref/rrefimportproc.html

Exporting database dump via phpMyAdmin to MS SQL

When I use the phpMyAdmin export, it has an option for MS SQL export compatibility. However, the resulting file includes many non-MS SQL compatible items, such as mediumtext and enum datatypes. How do I work around this issue?
mysqldump --compatible=mssql -uroot -p some_database > output_file_mssql.sql
vs
mysqldump -uroot -p some_database > output_file.sql
Looking at the difference between the two files will show you some things to check out.
I hope that helps some.
If you are unable to locate a way for phpMyAdmin to generate an exported file of the correct format, then you'll have to edit the resulting exported file to make it compatible with MS SQL. You may need to use regular expressions to, for example, replace ENUM datatypes.
If you find that you have to export data frequently, you may find that writing a short text processing script that you can re-run as needed will save you time.
Oh, and take care that your text editor or favorite scripting language can properly handle the character encoding of the file generated by phpMyAdmin.
This documentation seems pretty conclusive - http://www.waynezim.com/2010/03/how-to-export-mysql-database-to-mssql-using-phpmyadmin/