Lewis dot structures and exceeding the octet

I'm confused about the octet rule. As far as I understand, you need to complete the valence shell of the elements by sharing electrons.

Now, carbon has 6 electrons which means it has 4 valence electrons, but because it has 6 electrons in total it exceeds the first shell with 4 electrons. The second shell has 4 orbitals with 2 electrons each, so to complete the second shell I need 8 valence electrons, but I had read somewhere that the octet rule holds true until down to the 4th period. How can that be when say, magnesium, has 12 total electrons and thus it exceeds the the second shell with 4 electrons but the third shell needs 18 valence electrons to be complete, not just 8?

Secondly, I read that if the central atom has more then 8 electrons, then that's ok too? What happens if I have a choice of exceeding the 8 electrons by forming another bond with an adjacent atom or sticking those electrons on the opposite side of the adjacent atom?

Is one strictly wrong/preferable?

For the first part of your question, you are correct that Mg has 12 electrons, which are arranged in shells in the pattern 2 - 8 - 2. But magnesium is a typical metal in that it tends to lose electrons to form a cation that then forms solids by ionic bonding. The octet rule predicts that the resulting cation will be stablest if its outermost shell contains eight electrons. And indeed the magnesium ion is $\mathrm{Mg}^{2+}$, two electrons less than the atom, with an electron configuration of 2 - 8.
What would happen if you had asked about a non-metal atom in the third period, say Cl? This has an electron configuration of 2 - 8 - 7, and tends to form a single covalent bond (e.g., to form $\mathrm{Cl}_2$ or $\mathrm{HCl}$), giving a configuration of 2 - 8 - 8 rather than 2 - 8 - 18. The reason for this is that the first eight valence electrons occupy the $s$ (2 electrons) and $p$ (6 electrons) subshells, while any further electrons in the third shell must go into the $d$ subshell. These orbitals are both higher in energy than those from the first two subshells (which is why, as you go through the periodic table, the $4s$ shell is filled before the $3d$) and extend less far from the nucleus, so that they are much less likely to overlap other atoms' orbitals to form a covalent bond. So it is often energetically preferable not to put electrons into this subshell if possible, which is why the octet rule can still apply to elements in this period.
Of course, it is possible to put electrons into this subshell, which is why it is possible for the central atom to have more than an octet in compounds like $\mathrm{SF_6}$. This leads into the second part of your question, which, as Manishearth suggested, looks like a duplicate of Can an atom have more than 8 valence electrons? If not, why is 8 the limit?.