When what you say normally happens, it's one of these two situations:
1) The installation of the program has been corrupted: it happens for some reason the installation was not completed correctly (you interrupted it manually, the internet is unstable if it is online, the power went out while installed, among others). So when Linux tries to find the information needed to execute the mysql -u root -h localhost -p
command it does not complete the check and therefore throws an error like the one you show in your description.
Solution: Completely uninstall the program and install it again
2) The program path may not be added to the PATH environment variable: In very rare cases it may happen that the system did not automatically add the route of the program executable newly installed to the PATH variable. When not being added to the PATH variable, you can not execute it correctly from any directory from the terminal and if you try it you get an error like the one you show in your description.
Solution: You must add the path of the new program in your PATH variable so that it can be accessed globally from any directory in the terminal.
In your case: path export PATH=$PATH:/opt/lampp/bin/
I hope it helps. Greetings!