Messages on the Mac has no real export. You can print a conversation to PDF, but it only prints what is loaded on screen. The good news is that the whole history sits in a plain SQLite database, and with a few joins you can read any conversation with proper dates.
Where the data is
~/Library/Messages/chat.db ~/Library/Messages/chat.db-wal ~/Library/Messages/chat.db-shm ~/Library/Messages/Attachments/ Like most Apple databases, chat.db runs in WAL mode, so new messages can sit in chat.db-wal for a while before they reach the main file. Copy all three files together, and work on the copy:
mkdir -p ~/msg-copy cp ~/Library/Messages/chat.db* ~/msg-copy/ cd ~/msg-copy ~/Library/Messages is protected by macOS, so Terminal needs Full Disk Access (System Settings, Privacy & Security) or the copy fails with "Operation not permitted".
The same database exists on the iPhone as sms.db. In an unencrypted Finder backup it is stored under the SHA-1 of HomeDomain-Library/SMS/sms.db:
$ printf 'HomeDomain-Library/SMS/sms.db' | shasum 3d0d7e5fb2ce288813306e4d4636395e047a3d28 - so the file is 3d/3d0d7e5fb2ce288813306e4d4636395e047a3d28 inside ~/Library/Application Support/MobileSync/Backup/<device id>/. The tables are the same as below, and the phone often has years more history than the Mac.
The four tables that matter
-
message: one row per message.text,date,is_from_me,handle_id,service(iMessage or SMS),cache_has_attachments, andattributedBody(more on that below). -
handle: the other people.idis the phone number or email address. -
chat: one row per conversation.chat_identifieris the number or email for a one-to-one chat,display_nameis the group name if there is one. -
chat_message_join: links messages to chats (chat_id,message_id). A message'shandle_idtells you who sent it, but only this join tells you which conversation it belongs to.
Attachments go through message_attachment_join to attachment, whose filename column holds the path of the file under ~/Library/Messages/Attachments, along with mime_type and transfer_name.
Dates: nanoseconds since 2001
message.date is not a Unix timestamp. Apple counts from 1 January 2001 (978307200 seconds after the Unix epoch), and on current macOS the value is in nanoseconds. Older databases stored seconds, so if your dates come out in 1970 or 2001, that is why. The conversion is:
datetime(date / 1000000000 + 978307200, 'unixepoch', 'localtime') Find the conversation
SELECT c.ROWID, c.chat_identifier, c.display_name, COUNT(*) AS messages FROM chat c JOIN chat_message_join cmj ON cmj.chat_id = c.ROWID GROUP BY c.ROWID ORDER BY messages DESC LIMIT 20; List one conversation with readable dates
SELECT datetime(m.date / 1000000000 + 978307200, 'unixepoch', 'localtime') AS sent, CASE WHEN m.is_from_me = 1 THEN 'me' ELSE h.id END AS sender, m.text FROM chat c JOIN chat_message_join cmj ON cmj.chat_id = c.ROWID JOIN message m ON m.ROWID = cmj.message_id LEFT JOIN handle h ON h.ROWID = m.handle_id WHERE c.chat_identifier = '+15555550123' ORDER BY m.date; Run it with sqlite3 -readonly -header -column chat.db < query.sql. Output looks like this:
sent sender text ------------------- ------------ ------- 2025-03-14 13:00:00 +15555550123 hello 2025-03-14 13:01:00 me hi back The LEFT JOIN matters: in one-to-one chats your own messages often have handle_id = 0, which matches no row in handle, so an inner join would drop everything you sent.
Why some messages come out empty
On recent macOS versions, many rows have text set to NULL, and the content is in attributedBody instead: an archived NSAttributedString in Apple's old typedstream format. The query above shows those as blank lines. This is the most common reason "my export is missing messages" when people use the simple queries found online. Check how many rows it affects in your copy:
SELECT COUNT(*) FROM message WHERE text IS NULL AND attributedBody IS NOT NULL; Decoding typedstream in plain SQL is not practical, so this is where a ready tool helps.
The open-source option
imessage-exporter (GPL-3.0, Rust, brew install imessage-exporter) decodes attributedBody, handles tapbacks, edited messages and replies, copies attachments, and writes TXT or HTML:
imessage-exporter -f html -c full -o ~/msg-export It can also read an iPhone backup (-a iOS -p <backup folder>), filter by date (-s, -e) or by conversation (-t). If you need a readable archive and are fine with the command line, start there.
What I tested
On macOS 27 I copied chat.db and its WAL files to a scratch folder and checked every table and column named above against the real schema with sqlite3 -readonly. The Messages database on that Mac was empty, so I ran both queries on a test database built from the same CREATE TABLE statements with made-up rows, which is where the sample output comes from. I could not check the nanosecond dates or the attributedBody share on real messages there, so treat those two points as what the tools above and their docs describe, and check them on your own copy with the queries given.
Disclosure: I built a tool for this
I make Exhibitly at Kayabyte. It is a Mac app for one specific case: you need to hand a conversation to a lawyer or a court. It reads your Mac's Messages or an iPhone backup made in Finder (encrypted too, with your backup password), and exports a numbered PDF with dates, times and phone numbers, an Excel file with one row per message, a folder of the original attachments, and a verification page with SHA-256 fingerprints of the attachments and the databases it read. It also does excerpts and redaction, and WhatsApp chats.
The free preview has every feature but stops each export at the first 15 messages and watermarks the PDF, so you can check the result first. Personal is USD 39 once, the Evidence Bundle (Bates numbers, cover page, merging iPhone and Mac) is USD 69. It needs macOS 15 or later. It does not recover deleted messages, and it does not decide whether a court accepts them; that is a question for your court's rules or a lawyer.
If that is what you need: Exhibitly. For everything else, the queries above and imessage-exporter will get you far.
Written with help from an AI assistant; tested on macOS by me.
