I've lived in Berkeley and San Francisco for a combined six years. I'm so sad to be leaving this beautiful, special place. Housing can be very difficult to find in both cities, so I would recommend (a) watching Craigslist/PadMapper like a hawk, sending out emails with abandon, and trying your best to set yourself apart from other applicants, and (b ) networking -- asking friends, acquaintances, etc -- as you never know who will be able to connect you with an excellent set-up. The blessing/curse of the Bay Area is that many apartments are rent-controlled, so that many people end up renewing their leases for ages in order to keep their decades-old rates. I've been lucky enough to find roommates with rent-controlled places a few times over. It can be done, but it's not easy.
Berkeley: It's not the hippie enclave it used to be, but Berkeley is still quirky and charming. Safety is an issue throughout the city, but you'll be fine if you are smart about urban life (for example: don't engage with people behaving erratically, don't use your cell phone walking around, don't walk by People's Park late at night, etc). I also loved being able to safely bike everywhere, though the hills can be killer. As for places to live... The area southeast of campus (near Telegraph and into the hills) is full of undergrad dorms, frat houses, street punks, dive bars -- basically way too fun for anyone in their mid-20's. Instead, if you want to live close to campus, I'd recommend looking at a few neighborhoods.
North Berkeley: Most areas north of campus are going to be quiet, safe, and more family-oriented. There are few businesses, with the exception of those in the Gourmet Ghetto. That stretch of Shattuck Ave is lined with tons of foodie-centric shops and restaurants. A great choice for grad students.
Downtown Berkeley: A bit more commercial in feel, there's lots to do and the convenience of the BART station (the metro that takes you into San Francisco) is fantastic. I lived here, in a Craftsman home by Berkeley High and Trader Joe's, and absolutely loved it. The nearby police station didn't hurt. If you go a little south of that, you can live near the most wonderful grocery store on the planet, Berkeley Bowl.
West Berkeley: This sprawling area can really vary block by block, but there are two areas that could be good for grad students with cars. One is the bougie Fourth Street neighborhood, where you'll find Crate and Barrel, Anthropologie, the Apple Store, etc. The other option is staying close to the main thoroughfare, University Blvd, which is pretty busy and offers a lot of diverse food options.
Ashby, Oakland: This area is further away from campus, down Telegraph and on the border of Berkeley/Oakland. Oakland gets a bad rap, but, again, it's pretty safe if you exercise common sense. A friend of mine lived in a beautiful apartment steps away from Whole Foods, coffee shops, and the bus stop to campus.
San Francisco: Obviously, you know it's going to be expensive. Not just rent, but all of the other costs of living, too. If you're financially constrained, I'd highly recommend watching your budget, as it's easy to adopt a $5/day kombucha habit or blow an entire paycheck during brunch. Neighborhoods are also rapidly changing due to tech start-ups gentrification blah blah etc. Otherwise, however, this place is the absolute best. SF has lots of districts with very distinct personalities and weather patterns, so you'll want to make sure you're living in a place that feels right for you. For example: the Marina is full of rich yuppies and good weather, the Mission has its hipsters and tons of sunshine, the Sunset/Richmond are always foggy and home to surfers/Asian families...
SF State: Whether you have a car or not, I'd highly recommend living along a direct bus route to your school. For SF State, that can include the 28 and 29 bus lines, which will run through down 19th Ave and Sunset Ave in the Sunset district. The Sunset is an excellent choice for grad students, since it is far removed from the busy (and expensive) districts. If you live near the light rail (the N on Judah or the L on Taraval), you'll also be very close to shops/restaurants and a straight shot from downtown. You can also live further north along those same 28/29 bus lines, on the other side of Golden Gate Park, in the Richmond district. It's less busy/happening than the Sunset, but still affordable and full of neighborhood gems -- especially near Clement St. Alternately, the M light rail runs to SF State, so you can look along that route as well.
UCSF: The Parnassus campus is one of my very favorite neighborhoods in the city, especially because of all the cute storefronts near 9th and Irving. I'd highly recommend living close by, or anywhere along the N Judah. If you'd rather not live where you work, you can look at the UCSF campus shuttle map to identify other easily accessible neighborhoods. The shuttles are free and go to many locations throughout the city, so you can arrange a pretty stress-free commute door-to-door. For ex, I know one shuttle runs to and from the Laurel Heights/Pacific Heights, a really chic area.
As for those considering Oakland -- it's a great option, especially if you live close to BART and make sure that your specific neighborhood is safe. Oakland is enormous, so you're really going to want to zero in on where you're living. I have friends who love living in the Lake Merritt and Rockridge areas. Compared to its neighbors, Oakland is often much cheaper, culturally diverse, and parking-friendly (!!). Speaking of which, parking is going to be a bear... but it doesn't negate the usefulness of a car. For reference, I've lived this entire time in the Bay Area happily car-less -- but am also very thankful that my partner has one. I would highly advise against bringing a car if (a) you live in the more popular, public transit-accessible SF neighborhoods, e.g., northeast of Twin Peaks, or (b ) if you have to pay a fortune for parking. If you don't have a car, don't buy one until you get a feel for city life here. If you already have one, consider the costs (including the tickets you will inevitably get) and benefits. They can come in handy... especially when you're tired of grad school and want to escape to wine country for the weekend.