Exhibit 5 GRADY & ASSOCIATES ATTORNEYS & COUNSELORS AT LAW 20950 CENTER RIDGE ROAD, SUITE 100 ROCKY RIVER, OHIO 44116-4307 ------------------------- (440) 356-7255 Fax (440) 356-7254 July 17, 2002 Middlefield Banc Corp. 15985 East High Street Middlefield, Ohio 44062 Re: Dividend Reinvestment Plan Ladies and Gentlemen: We have acted as counsel for Middlefield Banc Corp. in connection with the Middlefield Banc Corp. Dividend Reinvestment Plan. We have examined such documents, records, and matters of law as we have deemed necessary for the purposes of this opinion. On the basis of the foregoing, we are of the opinion that Middlefield Banc Corp.'s shares of common stock that may be issued or transferred and sold according to the Dividend Reinvestment Plan will, when issued or transferred in accordance with the Dividend Reinvestment Plan, be duly authorized, validly issued, fully paid, and nonassessable. We hereby consent to the filing of this opinion as Exhibit 5 to the Registration Statement on Form S-3D filed by Middlefield Banc Corp. to effect the registration of common stock to be issued and sold according to the Dividend Reinvestment Plan under the Securities Act of 1933. Sincerely yours, /s/ Grady & Associates Grady & Associates