Implementing a simple global chat is pretty straightforward:
1- Don't use database
2- Implement filesystem based locking (multithread safe)
3- if there user wrote a new line, acquire lock and append the new line to the file.
4- releaase lock
5- send the last lines to the users. I recommend you to make a system call to "tail -n ??? [filename]", but you can implement you own last lines reading algorithm, much harder than it appears because you have stay friendly with kernel's readahead and disk cache.
You can have your chat log file in any format that fits you, (html, json, etc).
Then, for user based chat, just make the chatlog named after [user1]-[user2].chatlog, having user1 and user2 sorted alfabetically.
The hardest part is all the html an javascript needed, specially in multiuser chat, because you have to handle list of users and window opening.