how to generate ERD or UML for a database? - mysql

Referencing a previous question, it doesn't seem possible to easily autogenerate a UML or ERD graph. How can this be done? Even the the detail which describe fudforum.*; provides would do the trick, except that you can't use a wildcard.
Something like mysqldump -d -u <username> -p<password> -h <hostname> <dbname> but more readable?
It looks like devart doesn't run on Linux, but I'm looking into that.
mysql:
mysql>
mysql> describe fudforum.fud30_xmlagg;
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | | |
| url | varchar(255) | NO | | | |
| forum_id | int(11) | NO | MUL | 0 | |
| xmlagg_opt | int(11) | NO | | 2 | |
| last_load_date | bigint(20) | NO | | 0 | |
| custom_sig | text | YES | | NULL | |
+----------------+--------------+------+-----+---------+----------------+
7 rows in set (0.04 sec)
mysql>
mysql> quit;
Bye
thufir#dur:~$

mysql workbench can reverse engineer and create erd's
http://www.mysql.com/products/workbench/

I've tried many times to get MySQL Workbench to auto generate an ERD with relationship lines but always left frustrated. Most of the databases I was working with used MyISAM tables without defined foreign keys. That seemed to prevent Workbench from generating the relationships I wanted or I just couldn't understand how to make it work. I tried many other solution as well but again never found the easy solution I was looking for until I stumbled on this blog post at mysqlworkbench.org.
MySQL Workbench Plugin: Auto-Create Foreign Keys
The post is a full explanation on how to get Workbench to search all of your tables for candidate foreign keys in other tables. It even shows how to get a working GUI for it. The best part is that the article links to a Python script that can be installed in Workbench as a plugin so you it's all handled for you.
Once the plugin is installed you run it and give it a pattern to use for testing whether keys match. It then gives you a list of the keys it thinks match which you can select if you agree. Then you click a button and it generates the ERD for you with all the relationship lines in place. Hallelujah!
Many thanks to akojima at MySQL Workbench. Now if only I could take the Delorean back four years and find this when it was published in 2010.

There is a tutorial how to convert Oracle 10G to UML using Eclipse and Dali plugin.
You can just swap Oracle with your database sql connector inside Dali and it would do the job.

mysqlshow command:
mysqlshow fudforum

Related

How to create MySQL friendly view from a query result

How can I create a friendly view from MySQL query results like this image's examples to propose questions here, at stackoverflow, that are relationated with MySQL database problems.
I don't even know if friendly view is the correct term for this. But every time that I have to show my mysql table's data, I draw this information manualy.
I do something like this:
id_auto | name | type
1, john, person
I would like to do like the following examples:
I know this is a dumb question, but a search a lot and couldn't find any answer for this. Basically, I would like to produce data sample in this example's format from my pre existing mysql tables.
Taken from the MySQL website.
https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-output-table-format.html
5.6.1 Table Format
The table format is used by default for printing result sets when MySQL Shell is in interactive mode. The results of the query are presented as a formatted table for a better view and to aid analysis.
To get this output format when running in batch mode, start MySQL Shell with the --result-format=table command line option (or its alias --table), or set the MySQL Shell configuration option resultFormat to table.
mysql-sql> select * from sakila.actor limit 3;
+----------+-------------+----------------+----------------------+
| actor_id | first_name | last_name | last_update |
+----------+-------------+----------------+----------------------+
| 1 | PENELOPE | GUINESS | 2006-02-15 4:34:33 |
| 2 | NICK | WAHLBERG | 2006-02-15 4:34:33 |
| 3 | ED | CHASE | 2006-02-15 4:34:33 |
+----------+-------------+----------------+----------------------+

Ejabberd: Migrating Mnesia "passwd" table to MySQL "user" table

I have an (old) ejabberd instance that still uses 'internal' as authentication method. I installed a shiny new server (including MySQL) and am planning to migrate to it ASAP. I would like to avoid using Mnesia as authentication DB from then on.
Since my users' passwords are still stored in the Mnesia-database, I need to import them into the (new) MySQL DB on the new server. I succeeded in dumping the 'passwd' table and it is filled with entries like this one:
{passwd,{<<"flowie">>,<<"server.com">>},
{scram,<<"pHHeHwc5yaarPAshse7Ijuygtre=">>,
<<"4Qiv9ygiMLlzeZXUG6Bpyhygtgr=">>,
<<"dylctQFXYGXemMii1Pswe==">>,4096}}
To be able to correctly import these entries into the MySQL DB I need to figure out which field corresponds to which in the MySQL 'users' table:
+----------------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+-------------------+-------+
| username | varchar(191) | NO | PRI | NULL | |
| password | text | NO | | NULL | |
| serverkey | varchar(64) | NO | | | |
| salt | varchar(64) | NO | | | |
| iterationcount | int(11) | NO | | 0 | |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | |
+----------------+--------------+------+-----+-------------------+-------+
6 rows in set (0.00 sec)
I obviously know what the 'username' field is (and I think I can guess what the 'iterationcount' would be), but I want to make sure I get the others in the right order.
In one phrase: in what order are the 'password', 'serverkey' and 'salt' fields stored in an ejabberd Mnesia DB ? Where can I find info about this ? In the code perhaps ?
Note for the aspiring hackers among you: I did change the values, using a random character generator ;)
I configured ejabberd 18.03 with the option
auth_password_format: scram
and created an account. Its authentication information is stored like this in Mnesia:
{passwd,{<<"user1">>,<<"localhost">>},
{scram,<<"Eu9adR8M5NPIBoVKK917UKJQTtE=">>,
<<"0mRs0DKWvb8C0/fcVmTRP2elKOA=">>,
<<"UclT113AyXYlUAZgv3q0vA==">>,4096}}
Later I exported Mnesia to a SQL file using the command:
ejabberdctl export2sql localhost /tmp/localhost.sql
and the resulting file contains this line:
INSERT INTO users(username, password, serverkey, salt, iterationcount)
VALUES ('user1',
'Eu9adR8M5NPIBoVKK917UKJQTtE=',
'0mRs0DKWvb8C0/fcVmTRP2elKOA=',
'UclT113AyXYlUAZgv3q0vA==', 4096);

PuTTY outputs weird stuff when selecting in MySQL

I've encountered a strange problem when I was using PuTTY to query the following MySQL command: select * from gts_camera
The output seems extremely weird:
As you can see, putty outputs loads of "PuTTYPuTTYPuTTY..."
Maybe it's because of the table attribute set:
mysql> describe gts_kamera;
+---------+----------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| datum | datetime | YES | | CURRENT_TIMESTAMP | |
| picture | longblob | YES | | NULL | |
+---------+----------+------+-----+-------------------+----------------+
This table stores some big pictures and their date of creation.
(The weird ASCII-characters you can see on top of the picture is the content.)
Does anybody know why PuTTY outputs such strange stuff, and how to solve/clean this?
Cause I can't type any other commands afterwards. I have to reopen the session again.
Sincerely,
Michael.
The reason this happens is because of the contents of the file (as you have a column defined with longblob). It may have some characters that Putty will not understand, therefore it will break as it is happening with you.
There is a configuration that may help though.
You can also not select every column in that table (at least not the *blob ones) as:
select id, datum from gts_camera;
Or If you still want to do it use the MySql funtion HEX:
select id, datum, HEX(picture) as pic from gts_camera;

compare table structure (not content) from two different mysql database using query or third party tool?

I have two different database (mySQL) named
DatabaseOne
DatabaseTwo
Both DB have one table
DatabaseOne
DBOneTableOne
DatabaseTwo
DBTwoTableOne
Hoping Structure of both table is same because DatabaseOne structured designed using XAMPP phpmyadmin panel where DatabaseTwo structured designed by writing hibernate class first and than used hibernate create schema tool (hbm2ddl).
Structure of database:-
**DBOneTableOne**
Field | Type | Null | Key | Default | Extra
Id | int(11) | No | PK | | auto_inc
name | varchar(25) | No | | |
**DBTwoTableOne**
Field | Type | Null | Key | Default | Extra
Id | int(11) | No | PK | | auto_inc
name | varchar(25) | No | | |
I know one option to cross check manually database structure but it's time consuming and also I need to check more than 200 tables and I don't want to use hibernate reverse engineering wizard.
Is it possible to check both DB table structure is same using query??? Or any other third party software I need to use.

SQL SHOW TABLES lists a bunch of tables, but can't SELECT with them (No such table)

I have a database called apsc and if I run SHOW TABLES; on it, these are the results:
mysql> show tables;
+------------------------------------+
| Tables_in_apsc |
+------------------------------------+
| aps_application |
| aps_application_backup |
| aps_application_resource |
| aps_package |
| aps_package_configuration |
| aps_package_global_setting |
| aps_package_resource_configuration |
| aps_package_resource_setting |
| aps_package_series |
| aps_package_service |
| aps_registry_object |
| aps_registry_object_setting |
| aps_registry_object_tag |
| aps_resource |
| aps_resource_backup |
| aps_resource_requirement |
| aps_resource_requirement_backup |
| aps_settings_sequenses |
+------------------------------------+
18 rows in set (0.00 sec)
However, if I run SELECT * FROM aps_application I get this:
mysql> SELECT * FROM aps_application;
ERROR 1146 (42S02): Table 'apsc.aps_application' doesn't exist
In my /var/lib/mysql/apsc/ directory are a bunch of .frm files which leads me to believe these tables are InnoDB. However, if they were merely corrupt or missing from the data/log files in /var/lib/mysql/apsc/ibdata1 they should show up as table in use or what not, as I've had that problem with other InnoDB tables recently.
I believe these tables are part of Plesk as I had overwritten by databases files at some point and received errors about a missing view aps_application. Plesk is working fine now, so I doubt the table is corrupt.
Also, SHOW CREATE TABLE aps_application and SHOW CREATE VIEW aps_application both fail with the same error as select.
Edit: I'm logged in as root with full permissions. To check this I switched tables and SELECT worked like a charm. Also, If I am in phpMyAdmin and select this database it shows 0 tables unless I run SHOW TABLES; in the SQL tab;
ok, stab in the dark here but what if you fully qualify the table name? also, try to change the table name by putting a '_' after the name and see if you can select it then.
I had a similar issue. In my case it was the case sensitivity. select * from users is different from select * from USERS. So maybe you can try using the table name in upper case or the casing it was created with.
Turns out they weren't tables, and I never actually figured out what they are :(