A Schiff base fluorescent probe compound H2L (N′‐(4‐bromo‐2‐hydroxy‐benzylidene)‐3‐hydroxy‐2naphthohydrazide) was synthesized using 3‐hydroxy‐2‐naphthoic acid hydrazide as raw material. The structure of H2L was characterized by NMR, IR, MS, and XRD methods. The fluorescence performance of H2L was studied by UV and FS. The results show that in 1 : 4 water system /DMSO solution (water system: 20 % triethanolamine:0.1 mol/L L‐cysteamine acid=1 : 1), H2L can be used to quickly identify Mg2+ with an obvious fluorescence enhancement and redshift. A color change “light green→bright yellow” can be clearly observed with the naked eye. The Mg2+ concentration shows a good linear relationship in the range of 0–1.0×10−5 mol/L, with a detection limit of 1.77×10−7 mol/L with good stability and reversibility. The response mechanism was explored through Job's curve, NMR titration and MS, which showed that Mg2+ can form a 1 : 1 complex with H2L. A gel (SAL) was prepared by doping H2L into sodium alginate (SA). SAL was found to show good adsorption properties for Mg2+ and can be easily distinguished by the naked eye under ultraviolet light. The microscopic morphology and composition of SAL before and after Mg2+ adsorption were analyzed by SEM‐EDS. H2L can be used for the qualitative detection of Mg2+ in actual water samples without being affected by other common metal ions, and has potential application value in the field of environmental detection.