Bug #66821 Include referenced table name for Foreign Key in mysqldump XML output
| Submitted: | 14 Sep 2012 14:44 | Modified: | 3 Feb 2013 17:43 |
|---|---|---|---|
| Reporter: | Danny Kopping | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: mysqldump Command-line Client | Severity: | S4 (Feature request) |
| Version: | 5.5.27 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | fk, mysqldump, XML | ||
[14 Sep 2012 14:44]
Danny Kopping
[17 Sep 2012 7:01]
Valeriy Kravchuk
I'd call this a bug actually (incomplete information returned), not just a feature request:
mysql> create table t1(id int primary key, c1 int);
Query OK, 0 rows affected (0.31 sec)
mysql> create table t2(id int primary key, c1 int, foreign key(c1) references t1
(id));
Query OK, 0 rows affected (0.67 sec)
mysql> show create table t2\G
*************************** 1. row ***************************
Table: t2
Create Table: CREATE TABLE `t2` (
`id` int(11) NOT NULL,
`c1` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `c1` (`c1`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c1`) REFERENCES `t1` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.06 sec)
mysql> exit
Bye
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump -X -d -uroot -proot -P3312
test --tables t2
<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="test">
<table_structure name="t2">
<field Field="id" Type="int(11)" Null="NO" Key="PRI" Extra="" Co
mment="" />
<field Field="c1" Type="int(11)" Null="YES" Key="MUL" Extra="" C
omment="" />
<key Table="t2" Non_unique="0" Key_name="PRIMARY" Seq_in_index="
1" Column_name="id" Collation="A" Cardinality="0" Null="" Index_type="BTREE" Com
ment="" Index_comment="" />
<key Table="t2" Non_unique="1" Key_name="c1" Seq_in_index="1" Co
lumn_name="c1" Collation="A" Cardinality="0" Null="YES" Index_type="BTREE" Comme
nt="" Index_comment="" />
<options Name="t2" Engine="InnoDB" Version="10" Row_format="Comp
act" Rows="0" Avg_row_length="0" Data_length="16384" Max_data_length="0" Index_l
ength="16384" Data_free="9437184" Create_time="2012-09-17 06:57:50" Collation="u
tf8_general_ci" Create_options="" Comment="" />
</table_structure>
</database>
</mysqldump>
Foreign key related information is obviously missing.
[3 Feb 2013 17:43]
Shane Bester
The reason it's missing is that the XML representation comes from the output of "SHOW KEYS FROM 'table'", which is:
mysql> show keys from UserInformation\G
*************************** 1. row ***************************
Table: userinformation
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: userinformation
Non_unique: 1
Key_name: fk_UserInformation_User1
Seq_in_index: 1
Column_name: userId
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
2 rows in set (0.00 sec)
However, since the required information is available from information_schema, this is a valid feature request.
[21 Feb 2013 23:36]
Evan Cordeiro
You need to explicitly ask for the INFORMATION_SCHEMA database in this case: mysqldump --xml --skip-lock-tables --databases mydatabase INFORMATION_SCHEMA Note: I've used this for introspection, but I haven't tried to rebuild a schema with it. I don't know if it's possible to integrate this data into a rebuild out of the box, and at any rate would certainly require some work if you were rebuilding a schema on a server with multiple databases. from mysqldump page at http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html "mysqldump does not dump the INFORMATION_SCHEMA database by default. mysqldump dumps INFORMATION_SCHEMA only if you name it explicitly on the command line, although currently you must also use the --skip-lock-tables option. Before MySQL 5.5 mysqldump silently ignores INFORMATION_SCHEMA even if you name it explicitly on the command line."
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.