I am 6.2 feet tall, and I have a mountain bike that is 17 inches long. I know it looks bit small for me, but will I hurt myself by riding this bicycle? What should be the preferred bicycle length for someone my height?
That does seem small for your height. Are you hunched over while riding? Does your leg stay fairly bent all the way through your pedal stroke? Are you comfortable after riding for a few hours?
The preferred bicycle size depends on more than just your height, and is best figured out by going into a bike shop, getting some help from the staff, and trying out a few bikes.
Ideally: You want to have the seat up high enough that at the bottom of your pedal stroke, your leg is just slightly bent, similar to how your leg naturally works when you walk. You want to be able to bend forward at the waist a comfortable amount that you could hold for hours, put your hands forward into a natural-feeling position, and have the handlebars right there. You don't want to have to 'reach' for the pedals. You don't want to have your knees bent too much. You don't want to be hunched over. You don't want to be stretched out. You don't want to be leaning on the handlebars. You want to be comfortable.
It's not just your height that affects what size bike you want. It's how long your legs are, how long your torso is, how long your arms are, how flexible you are, and how much core strength you have.
2 people that are both 6'2" may have very different proportions (long legs with short torso, short legs with long torso, or anything in between) have different sizing needs.
Generally, bike size affects both how long the bike is (from headset to where the seatpost goes), and how tall the bike is (from pedals to where the seatpost goes). Both go together.
There are 3 contact points: pedals, saddle and handlebars. You can't really move the pedals, except to get slightly different length crankarms. However, you can get a longer seatpost, seatposts with different amount of setback, and you can move the saddle around a fair bit. You can also get different stems and different handlebars to move the handlebars around quite a bit. All that means that for a bicycle that's only a couple sizes too small, you can probably still adjust it to give you a reasonable fit.
With an MTB that's ridden off-road, you may want a frame that's a touch small, so that when you fall with the bike between your legs, your feet can hit the ground well before your crotch hits the top tube.
In other words: can you get the fit right on this bike? If it feels good to ride for hours and doesn't give you any pain, it's probably fine...