The following three "tricks" took me 17 years to discover, but it will only take you 5 minutes to learn. Your understanding of what makes a community tick will be better forever.
These fundamental principles apply to building a thriving community, regardless of what technology or medium you choose. I know because we failed in every one of them many times over. And from failure, you learn.
A community is a group of people united by a common trait, need, interest or preference. Importantly, it includes notions of belonging and exclusivity. A strong community requires unity. Unity is formed when the common purpose is distinct, undiluted and constantly reinforced.
At the same time, everyone is unique in their own special way. People's personalities, their beliefs, ideas, physical characters can all never be the same. Humans are incredibly diverse, each representing unique combination of likes and dislikes.
As a community leader, you have to make the hard choice and stick to it.
Say, you are operating a restaurant, and these are the locals:

Bob, Sue and Tam make up a great Pizzarians community. You start as a Pizza Parlour. Remember this:
The best bet is to focus on Just One Thing - pizza.
Affinity starts from that feeling that part of us is invested in the community, that we have a right to belong and feel welcome.

There are so many ways to say "Hi!". You can send a quick message or a video, or just leave a comment on their timeline. Even something as simple as "add to friends" on your site or connecting via an external social network works wonders. In time, many become friends and form the foundation for the future greatness.
Engaging everyone will become increasingly difficult as your membership base grows, but there is a trick. Whenever you can, go and say "Hi" to the ACTIVE members. For example, if you're operating a UNA-based site, there's a tab for Active profiles. Check those often and make sure to greet people you haven't greeted yet.
The practice of being welcoming and accommodating will catch on with the rest of the community and eventually you'll see your core group greeting newcomers. Pure magic.
Everyone longs for recognition. That sense that we have some say and that our perspectives are appreciated and respected. When our input influences decisions and shows in the resulting product (or state of the community), we feel strong connection.
Imagine for a moment that you are shopping for a new car. You like some fancy new Volvo except the wheels design feels wrong. In passing you tell the dealer - "Hey, I wish those rims had five Y-shape spokes with black sides". And the dealer goes - "Wow, interesting idea! I'll pass it on to our design team."

What would be the result of such experience?
The world is full of incredibly creative and intelligent people, and most of them love sharing what they know or think. You don't have to follow every advice. Just listen and let them know that you listen. Use the best ideas to advance your core offering and make sure to give credit for them.
Voila! Three tenets to remember.