All records from the table
SELECT * FROM tbl
In a specific table
SELECT * FROM wp_posts
Based on Wordpress Database ERD , to get attachments, this should be close
SELECT * FROM wp_posts WHERE post_type='attachment' and post_status='inherit'
This will give you the attachments as well as the parent entry that it is associated with if you need some kind of context
SELECT posts.ID, posts.post_title AS title, posts.post_content AS content, files.meta_value AS filepath FROM wp_posts posts INNER JOIN wp_posts attachments ON posts.ID = attachments.post_parent INNER JOIN wp_postmeta files ON attachments.ID = files.post_id WHERE files.meta_key = '_wp_attached_file'
If I'm not mistaken, filepath gives you a link to the place on disk where the image files are actually stored. If that's all you need, just go to it (or ftp if it is deleted) and grab all the files from there.
source share