Parse RDF file and save to MySQL

Want to parse RDF file and save to MySQL ? Want to schedule and automate this importing task?

To import Xml format RDF file (.rdf, .owl) to MySQL (MariaDB, Percona), https://www.withdata.com/blog/rdftomysql/mysql-import-rdf.html

To import RDF Turtle file (.ttl, .n3) to MySQL (MariaDB, Percona), https://www.withdata.com/blog/rdftomysql/ttl-to-mysql.html

To import RDF N-Triples file (.nt, .ntriples) to MySQL (MariaDB, Percona), https://www.withdata.com/blog/rdftomysql/n-triples-to-mysql.html

To import RDF N-Quads file (.nq, .nquads) to MySQL (MariaDB, Percona), https://www.withdata.com/blog/rdftomysql/n-quads-to-mysql.html

RDF → MySQL reference

Type mapping

Value kindin RDFin MySQL
Int"1234"^^xsd:intINT
Bigint"9007199254740993"^^xsd:longBIGINT
Decimal"1234.56"^^xsd:decimalDECIMAL(p,s)
Float"1.234e10"^^xsd:doubleDOUBLE
Textplain literal without a datatypeVARCHAR(n)
Long textplain literal; newlines allowed insideLONGTEXT
Date"2026-09-18"^^xsd:dateDATE
Datetime"2026-09-18T14:30:00Z"^^xsd:dateTimeDATETIME
Binary"base64..."^^xsd:base64BinaryLONGBLOB
Boolean"true"^^xsd:booleanTINYINT(1)
JSONa literal, or reified as its own sub-graphJSON

Dialect differences

RDF is a file format and MySQL is a database server, so the target has to be told the types the file never carried – the rows below are where the two sides diverge.

Propertyin RDFin MySQL
port—3306
identifiersXML attribute quoting; entities for reserved characters`backtick`
row limit—LIMIT n
datesxsd:dateTime typed literalsDATETIME, TIMESTAMP, DATE, TIME
long text—TINYTEXT / TEXT / MEDIUMTEXT / LONGTEXT
binaryxsd:base64Binary typed literalsBLOB / TINYBLOB / LONGBLOB
separatorXML elements (rdf:Description / rdf:resource)—
encodingDeclared in the XML declaration—
typingEvery value is a resource or a typed literal—
shapeGraph of triples; there are no rows or columnsTables of rows and columns
ceilingWhole document is usually parsed into memory—

Command line

SideCommand
MySQLmysqldump, or mysql -e "SELECT ..." > out.csv
MySQL (load)mysqlimport, or LOAD DATA INFILE

XML to MySQL without the manual work

For batch jobs, large files and scheduling use the XML to MySQL converter — an offline desktop app for Windows, Linux and macOS. Free trial.


Posted

in

by

Tags: