What lessons did you learn while doing your PhD? What lessons did you learn while doing your PhD? What advice would you give somebody just starting off with their PhD that could save them time and grief?

I have collected some of the lessons I learned along the way. Feel free to add your own lessons learned, and link your thesis to give people an idea of just how different a thesis can be in different subjects and parts of the world.
My background: I completed an engineering degree, and worked for a few years before I started a PhD in Telecommunication Systems in Sweden. I wrote my thesis on the subject of performance measurements in complex networks. The thesis is an extremely unwieldy thing, trying to sum up experiences from three different projects.

My lessons learned

Planing your work:


Try to keep your office hours. I started off working from 7 am to around
11 pm most days, eating all three meals on campus. This was not good
for my productivity (so much time wasted!), relationships (with
friends, family or SO), or mental health. Things got a lot better
when I started working "normal" office hours, only working evenings
when close to deadlines.
Have a 5 year plan (how are you going to get your PhD done?), a 5 month plan (What's the current research objective?), a 5 week plan (How are you moving towards the objective?) and a 5 day plan (What's the plan for the week?). These should be in writing. They help you structure your work, and makes it a lot easier to say no to things that did not help you towards your PhD. 
Keep track of the learning objectives in your PhD program, and the requirements for your PhD. If you are writing an article thesis you need to have a publication when you are halfway in. If you are writing a monograph, you should have started writing about halfway.
Many universities will happily use PhD students as cheap teachers on full time. Be careful to monitor how much time you spend as a TA.


Coursework:


If you have coursework requirements make sure that you have them fulfilled with time to spare. It's not fun to wrap up the PhD and then return to take additional courses to get your degree (I have a friend who had to do this, being a few points off, just because a mandatory course that wasn't offered that last year...)
Three subjects are useful for almost every PhD: Scientific methods, Scientific Writing and Statistics. Take courses in these three subjects as early as possible. 
Avoid undergraduate courses, they are often a waste of time.
Specialised courses in your field of study are often fun and inspiring, but try not to overspecialise too early.
There are a lot of summer schools offered, which is a great if you want to meet new people and learn from some very good teachers at other universities.


Publishing:


Learn to structure your writing. Use CARS or some other model!
Rejections happen, and waste a lot of time. Aim low with early papers, learn the skills of the trade, and save your opus for later.
Don't start your PhD with a methodology paper aimed for high profile publications (I had my first paper rejected 5 times, which was not very fun). 
Publishing in small, national, conferences and publications is a good way to meet people, share ideas and get inspiration how to move forward. You can usually reuse much of the ideas in international publications.
In most cases you will need internationally recognised journal or conference publications. About half way you should start aiming for these.
If your advisor wants you to publish in Nature/Science/Cell/Proceedings of the IEEE etc, FYL. 
If you are working with companies or other external entities, make sure you know what you can actually publish. It hurts to do a lot of work, and then later learn that it is all under an NDA and you can't publish it. 


Sanity:


Advisors rarely have as much time as you want. Make sure you have some co-advisors which can help you when your primary advisor can't help you. Make sure you credit your co-advisors. I got one that saved my PhD.
Work-life balance is important. Make sure you go home, take care of yourself, sleep properly. 8 hours of productive work is much better than 16 hours of lacking productivity
The feeling of "wasting time" is very common when doing a PhD. If you find yourself at 10 pm, still at work, reading PhD Comics... Just give up and go home. We all do it. 
In the end, a PhD is a Marathon, not a sprint. Slow, methodical work without giving up will get you there eventually. 
Homeland support is important. Nurture it. Pets, family, friends... Anything that forces you to focus on what's really important in life (and that is not the PhD, even if it feels like that)
PhD comics helped me deal with some of the trauma.