Hierarchical porous carbons (HPCs) have been successfully prepared by a facile carbonization and subsequent CO2 activation process using corncob as a natural carbon precursor and Mg(C2H3O2)2 as a MgO nano-template precursor. The prepared corncob-based hierarchical porous carbons (C-HPCs) with desirable micropores and mesopores feature the excellent absorbency of gas (i.e., CO2 and CH4) and solution (i.e., methylene blue (MB)). Increasing the ratio of Mg(C2H3O2)2/corncob enlarged the specific surface area up to 1004 m2/ g, micropore and mesopore volumes, CO2, CH4, and MB adsorption capacities (112, 31 and 230 mg/g after 325 min, respectively). The results indicated that the pore structures of C-HPCs can be easily and suitably controlled by the amount of the template precursor and CO2 activation effecting concurrently, which leads to fascinating adsorption capacity for CO2, CH4, and MB.