Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store XML data into a mysql database? I don't want foreign keys like crazy

If my XML data is very complex, is there a way I can store this in DB?

like image 408
TIMEX Avatar asked Feb 05 '10 00:02

TIMEX


People also ask

Can you store XML in MySQL?

The most common way to store XML in MySQL is to use the LOAD_FILE() function to open an entire XML document, store it in a variable, and insert the variable into a table column.

Can you store XML in database?

"You can store XML in a database designed specifically for XML, in a modified object database, or in a relational database."

Should I store XML in database?

It's neither bad or good to do store XML in a DB. You just have to consider your requirements and how the data is used. If your data is machine produced and consumed, and it is only in XML to transport between apps, then a DB makes sense.

How do I import XML into MySQL?

To import data from a XML file into a MySQL table, select the table in Object Browser and select Table -> Import -> Import XML Data Using Load Local... or(Ctrl+Shift+X). Tables: The list of all tables of the currently active database is shown. Select the Table from the list box.


1 Answers

The "regular" way is to store XML in a CLOB (Character Large Object) and MySQL supports CLOB with 4 data types:

  • TINYTEXT - A CLOB column with a maximum length of 255 (2**8 - 1) characters.
  • TEXT - A CLOB column with a maximum length of 65,535 (2**16 - 1) characters.
  • MEDIUMTEXT - A CLOB column with a maximum length of 16,777,215 (2**24 - 1) characters.
  • LONGTEXT - A CLOB column with a maximum length of 4,294,967,295 or 4GB (2**32 - 1) characters.

Using one or the other depends on your needs.

like image 185
Pascal Thivent Avatar answered Oct 11 '22 22:10

Pascal Thivent