There are two parts to this question. One is about whether you can buy a mastiff and have it fight for you; the other is about whether a squire can help with this somehow.
Can you buy a mastiff and have it fight for you?
The rules say that you can buy a mastiff. (PH p157) I haven't been able to find any rules about training a mastiff or getting it to fight for you in combat. You can use the Animal Handling skill to "calm down a domesticated animal" or "prevent it from being spooked" (p178) but there aren't any rules for using that skill to persuade an animal to attack.
Most of the things you're fighting will do way more than 5 damage on a hit, which means they can kill your dog easily if they decide they want to. Your dog knows this, so persuading it to fight next to you will likely be very difficult. It's unlikely that you can pay someone else to train your dog for you; you need a personal bond with your dog that will make it willing to risk its life for you, and a trainer can't forge that bond for you. You'd have to talk to your DM about the details, but it would likely take a lot of time and a high roll on the Animal Handling skill.
Does your mastiff need to be given orders, and if so, can your squire do that for you?
Once you've convinced a dog to risk its life for you in battle, it seems like teaching your dog to follow you around and attack the things you attack should be a much easier task. Your dog wants to stay close to you anyway, and if you get in combat, your dog can figure that out without a direct order.
The rules for your retainers are that they "do not fight for you" and "will not follow you into obviously dangerous areas (such as dungeons)". It's a bit ambiguous whether these rules apply to your squire, but if your squire isn't willing to fight for you then he's probably not willing to follow you into dangerous areas either. So most of the time you get in combat, your squire won't be physically present at all. (And if you're not in an obviously dangerous area, your squire probably doesn't have your attack dog ready either.)
Should your DM let you do this?
In most D&D adventures, people -- even adventurers -- don't walk around with attack dogs. This suggests that there's probably something about having an attack dog that makes it not worth the effort for most people to do. If your DM tells you how hard it is to get an attack dog, and the cleric looks over and says: "Wait, it just costs 25gp for a dog, and it can deal damage in combat or soak up an incoming attack? I've got 250gp right here, and my wisdom gives me a great Animal Handling skill -- I'll take ten of them!", then something has gone wrong with the DM's worldbuilding.
Likewise, if the DM restricts dogs to one per person, and then every character in the party decides it would be a good idea to buy a dog, then something has gone wrong. If everyone wants to buy a dog, but they don't because having a dog is your character's thing and they don't want to be a bunch of copycats -- that is still a problem.
Whatever terms your DM gives you, you should expect to spend a significant amount of time or skills or money on the dog, enough that it wouldn't be worth the effort for most adventurers.
My suggestion would be that maybe taking care of a dog eats up a lot of downtime, and most characters don't want to spend the effort. But one of your retainers could be a houndmaster, whose job is to feed and entertain and care for your dogs when you're not using them. (In much the same manner that a groom cares for your horse when you're not using that.)