Those two things you just described are not in any way the same thing.
Science: propose a possible explanation of observed phenomena, an explanation based on an informed understanding the underlying principles that control that phenomena; rationally design a controlled series of tests of the explanation by isolating variables one at a time, and identifying patterns in the results; refine initial explanation as necessary to conform to those new patterns, and continue the process forever as new understanding leads to new questions.
Trial and error: try a random thing and see what happens, then try another random thing and see what happens, and keep doing that until you get what you want, and then stop, with no understanding or attempt to understand the underlying factors that lead a given set of conditions to a given result.
Trial and error is not science. Trial and error is random fucking around. Trial and error is what you do when you have no hypotheses to test, no theories to guide you, no understanding of what’s actually happening, and no interest in developing any those things.