{"id":27787,"date":"2025-05-06T08:08:50","date_gmt":"2025-05-06T08:08:50","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=27787"},"modified":"2026-03-07T02:01:43","modified_gmt":"2026-03-07T02:01:43","slug":"store-rtf-in-mysql-text","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/clob\/store-rtf-in-mysql-text.html","title":{"rendered":"Store RTF in MySQL TEXT"},"content":{"rendered":"<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Rich_Text_Format\">RTF<\/a>(Rich Text Format) can be stored as MySQL TEXT data.<\/p>\n<h2>1. MySQL TEXT Type Overview<\/h2>\n<p>MySQL offers multi-level TEXT types:<\/p>\n<ul>\n<li>TINYTEXT (255B), TEXT (64KB), MEDIUMTEXT (16MB), LONGTEXT (4GB)<\/li>\n<\/ul>\n<p>MEDIUMTEXT\/LONGTEXT are recommended for RTF storage (covers most scenarios).<\/p>\n<h2>2. Pure SQL Implementation Steps<\/h2>\n<h3>Step 1: Create Table with MEDIUMTEXT Field<\/h3>\n<pre>CREATE TABLE RTF_DOCS (\r\n    DOC_ID INT PRIMARY KEY AUTO_INCREMENT,\r\n    DOC_NAME VARCHAR(100) NOT NULL,\r\n    RTF_CONTENT MEDIUMTEXT NOT NULL, -- 16MB capacity (ideal for RTF)\r\n    CREATE_TIME DATETIME DEFAULT CURRENT_TIMESTAMP\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- Unified UTF-8 encoding\r\n<\/pre>\n<h3>Step 2: Insert RTF Text into TEXT Field<\/h3>\n<pre>-- Method 1: Insert short RTF text directly\r\nINSERT INTO RTF_DOCS (DOC_NAME, RTF_CONTENT)\r\nVALUES (\r\n    'test.rtf',\r\n    '{\\\\rtf1\\\\ansi\\\\deff0 {\\\\fonttbl {\\\\f0 Calibri;}} \\\\pard\\\\f0\\\\fs22 MySQL RTF Test\\\\par}'\r\n);\r\n\r\n-- Method 2: Import external RTF file (MySQL command line)\r\n-- 1. Convert RTF to UTF-8 first\r\n-- 2. Import with the following commands (log in to MySQL client)\r\nUSE your_database;\r\nSET @rtf_content = LOAD_FILE('\/path\/to\/test.rtf'); -- File must be accessible to MySQL server\r\nINSERT INTO RTF_DOCS (DOC_NAME, RTF_CONTENT) VALUES ('imported.rtf', @rtf_content);\r\n<\/pre>\n<h3>Step 3: Query\/Edit RTF Content<\/h3>\n<pre>-- Query full RTF content\r\nSELECT DOC_NAME, RTF_CONTENT FROM RTF_DOCS WHERE DOC_ID = 1;\r\n\r\n-- Truncate RTF preview (first 200 characters)\r\nSELECT DOC_NAME, SUBSTRING(RTF_CONTENT, 1, 200) AS RTF_PREVIEW FROM RTF_DOCS;\r\n\r\n-- Update RTF content\r\nUPDATE RTF_DOCS \r\nSET RTF_CONTENT = '{\\\\rtf1\\\\ansi\\\\deff0 \\\\pard\\\\f0\\\\fs30 Updated MySQL RTF\\\\par}'\r\nWHERE DOC_ID = 1;\r\n<\/pre>\n<h3>Step 4: Delete RTF Record<\/h3>\n<pre>DELETE FROM RTF_DOCS WHERE DOC_ID = 1;\r\n<\/pre>\n<h2>3. Simplify MySQL TEXT RTF Management with DBBlobEditor<\/h2>\n<p>DBBlobEditor addresses MySQL TEXT RTF management pain points:<\/p>\n<ul>\n<li>\n<h3>View \/ Edit RTF<\/h3>\n<p><a href=\"\/blog\/mylobeditor\/view-rtf-data-in-mysql-text-read-display-rtf-from-mysql-text-column.html\">Visually browse and edit RTF content in MySQL TEXT fields<\/a> without command-line tools.<a rel=\"noopener\" href=\"\/images\/lobeditor\/blob-rtf.png\" target=\"_blank\">?<\/a><\/li>\n<li>\n<h3>Insert RTF into MySQL TEXT<\/h3>\n<p><a href=\"\/blog\/mylobeditor\/import-rtf-to-mysql-text.html\">Bulk import RTF into MySQL TEXT<\/a> with few clicks.<\/li>\n<li>\n<h3>Extract MySQL TEXT to RTF<\/h3>\n<p><a href=\"\/blog\/mylobeditor\/mysql-export-text-to-rtf.html\">Bulk export MySQL TEXT to RTF files<\/a> visually, avoiding complex scripts.<\/li>\n<\/ul>\n<h2>4. Notes<\/h2>\n<ul>\n<li>LOAD_FILE() only reads files on the MySQL server; grant FILE permission first: `GRANT FILE ON *.* TO &#8216;user&#8217;@&#8217;localhost&#8217;;`<\/li>\n<li>Adjust MySQL configuration `max_allowed_packet` (default 4MB) for large RTF inserts<\/li>\n<li>MEDIUMTEXT (16MB) suffices for most RTF files; use LONGTEXT for extra-large files<\/li>\n<\/ul>\n<hr \/>\n<h3>Related Guides<\/h3>\n<ul>\n<li><a href=\"\/blog\/clob\/store-rtf-in-clob.html\">Store RTF in CLOB: Complete Guide for Character Fields Across Databases<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-db2-clob.html\">Store RTF in DB2 CLOB<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-oracle-clob.html\">Store RTF in Oracle CLOB<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-sql-server-nvarcharmax.html\">Store RTF in SQL Server NVARCHAR(MAX)<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-postgresql-text.html\">Store RTF in PostgreSQL TEXT<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-sqlite-text.html\">Store RTF in SQLite TEXT<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>RTF(Rich Text Format) can be stored as MySQL TEXT data. 1. MySQL TEXT Type Overview MySQL offers multi-level TEXT types: TINYTEXT (255B), TEXT (64KB), MEDIUMTEXT (16MB), LONGTEXT (4GB) MEDIUMTEXT\/LONGTEXT are recommended for RTF storage (covers most scenarios). 2. Pure SQL Implementation Steps Step 1: Create Table with MEDIUMTEXT Field CREATE TABLE RTF_DOCS ( DOC_ID INT [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4526],"tags":[100,1323,2106,176],"class_list":["post-27787","post","type-post","status-publish","format-standard","hentry","category-clob","tag-clob","tag-mysql","tag-rtf","tag-text"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/27787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=27787"}],"version-history":[{"count":5,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/27787\/revisions"}],"predecessor-version":[{"id":45454,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/27787\/revisions\/45454"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=27787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=27787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=27787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}