this is sort of a huge qustion but let's try :-)
Database: it's an N:N relation so you need 3 tables 1) Posts which have an id 2) tags which have an id 3) posts_tags with post_id and tags_id this would make it possible to have several tags for one post
how to store: create post which gives you an post_id then you add the tags by inserting this newly created post_id with the assigned post_ids into the posts_tags table
how to retrieve according to a tag: select * from posts_tags where tags_id = x;