Specialization is key to survival on higher difficulties where the opportunity cost of producing a new "thing" is very high. This doesn't mean you're going to completely ignore everything else and focus just on one thing per city, but it does mean you're going to change your city's priorities based on the city's specialization.
Starting Out
I tend to follow this formula:
Your first city should just generally be wherever you started. If you've got a starting military unit, explore your immediate surroundings with that unit before you move your settler. Your settler can typically move one tile and found on the same turn, so if there's significant bonuses you can put within your potential borders one tile away, take them.
Your second city should be founded somewhere near production bonus tiles, like hills and forests. Bonus points if you can land some Sheep, Cows, or Horses, and double bonus points if you can find Iron. Finding Iron takes science, which you might not have by the time you're ready to found your second city.
Your third city should be founded somewhere with significant gold potential. Shore tiles are good for this (but found on the coast so you can build the appropriate buildings to use them!), and many resources also provide gold.
Don't worry too much about optimizing the distance between your cities - move a bit further away if you can get some significant bonus tiles or if your starting location doesn't have much in the way of nearby hills. Better city locations are higher priority than squeezing every last tile into a city radius. Rivers are pretty good to found next to, as there are some buildings that can only be built next to rivers, and there is typically an abundance of tiles that are good for food production. Avoid expanses of Tundra, Snow, Desert, or Mountain tiles, as these are limited in their usefulness.
Beyond these three cities, you want to found new cities when you can secure a new Luxury resource (to offset the happiness hit), and hopefully at the same time secure new strategic resources or key areas of the map. Found when you can defend the new city, and when you can absorb the happiness hit.
Specializing
Okay, with that out of the way, let's discuss specialization.
There are two key things you're going to do to specialize your cities:
- Build specialized improvements with workers
- Build specialized buildings
Worker Improvements
Workers should prioritize building special improvements on special tiles whenever possible, especially Luxury and Strategic resources. Beyond that, I tend to build one of four improvements:
- Near all cities, build at least some Farms. Ideally, these should be near rivers or on flood plains. Your capital should have more farms than the other cities, but every city should have at least 3 or 4.
- Near production cities (like starting city #2 above), build Mines or Lumbermills - Lumbermills unlock late, but they let you keep the forest production bonus, so it's worthwhile to leave at least a couple of tiles that have forests unimproved. Hill tiles with forest are better off chopped down with mines on them.
- Near your economic cities (like starting city #3 above), build Trading Posts. The neat thing about Trading Posts is that they can be built on forest tiles without removing the forest. This gives you more production from the tile at the expense of food.
Workers also need to establish efficient road links between all your cities - this is key to gold production, and key to surviving a military incursion.
City Buildings
Your science cities (ie, the capital) should be focused on increasing population and science. Many science buildings focus on the number of people in the city, so building things like Granaries and Aqueducts are key to boosting science output. Likewise, you won't have much science without Libraries or similar.
Your production cities (ie, #2) should be focused on cranking out military units. Thus, you need to build production increasing buildings (Workshop, Factory, etc) and military buildings (Barracks, Armory). As the difficulty ratchets up, you're going to be more inclined to buy the buildings so that you can focus on military. Without significant military, the AI will steamroll you for sure.
Your economy cities (ie, #3) should focus on gold, gold, and more gold. Markets, Banks, etc. Maintaining and increasing your population is a close second. Just below that is Science production.
Wonders will come along, and you should stick these in the cities that would benefit from stacking the bonuses. Similarly, great people should be assigned to build their special tile improvement near the corresponding specialized city. I sometimes will consume extra scientists or engineers to rush key research or wonders, though.
This is not to say that you shouldn't build Granaries or Aqueducts everywhere - population is important. And happiness buildings should be everywhere as well. At least some culture production in each city can be beneficial. But I'd urge you not to build a Library in your production city, or a Barracks in your economy city. These are just wastes of your production and gold per turn in some cases.
If you get to the point where you have all the key buildings built everywhere, it's probably time to consider expanding if you can. That means some military production to defend your new borders, more workers and a new settler. If you get to the point where you can't expand any further, it's clobberin' time. Crank up military production and go to war.
As the game progresses, your starter cities will start to flourish and may be able to take on a more general role. If/when this happens depends on the difficulty to a large degree. At lower difficulties, you'll find yourself massively overpowered very quickly, while at higher difficulties your military cities will probably crank units from start to finish.
But... But...
You might think "But I didn't build barracks in most of my cities, my units will be terrible!" - that's OK! Build siege units that will be racking up XP at your military/production cities, and build front line infantry meat grinder units at the others. You're going to lose units in a war, and keeping your low-cost "green" units at the front lines is a smart way to play.
There's also the concern of not building Markets or Libraries everywhere. These seem like no-brainers, but the impact of building them tends to be small outside of the cities that are designed to use them. For instance, a Market in a city with no trading posts is a waste. Similarly, if you haven't maxed out your population, a Library is going to produce a minuscule amount of science.
There's also the "City Focus" toggle, which I tend to ignore except in extenuating circumstances. Generally I'd suggest just leaving it at "Balanced" unless you're rushing production on something important (ie, military units or a wonder) or you're trying to avoid growth to halt the happiness penalty.
An Example
I started up a game at an advanced age so that I could demonstrate how I select city locations for my first two "specialist" cities. My capital is Constantinople (not Istanbul), and it is in a pretty good spot. I've got Wine, Marble, and Iron, with some Ivory nearby. It's also right on a river with a good amount of different tiles. This was my starting spot, and I give it a thumbs up.
Now I've got to pick two more spots. Here's the situation to my north and south:
North of the capital
South of the capital
I've circled in red the tiles I've picked as being good candidates. To my north, I've got Pearls and some more Iron, but there's not a real good amount of hills or forests. It's a decent spot, to be sure, and no doubt I will settle here eventually.
Northwest is some hills, but mostly it's desert. There's not a lot to recommend it.
Directly to my east there is just a vast plain with not a lot going on. I want to find some luxury or strategic resources to found near in addition to finding a "good spot" so I'll probably pass on this for now.
Southwest seems promising. Here I've got extensive hills and forests, plus Stone, Sheep, Horses, and Dyes. This is a pretty good location for my second city. I'd like a couple more hill tiles, but this will do.
To the southeast, I have another river, with Wine, Ivory, and eventually Stone and Deer. I'd like it better if I didn't already have Wine and Ivory, but perhaps I can sell the excess for some easy gold.
From here, I'll probably expand east as happiness permits. Farther to the northeast I've got an area overflowing with Iron, which will make a decent second military/production city. I might take some of the land to the north as well, but this is lower priority so close to my capital - it's unlikely anyone can claim this and defend it successfully.
If I can claim some land in the early game, that will make the later game a bit easier. My strategy tends to be conquer, conquer, conquer, so as long as I can carve out 4 or 5 cities, I'm probably good.