It will be safer to first encrypt the data and then paste it into mysql. Otherwise, the data can be "sniffed" while listening to traffic between the application server and the database.
Another point to consider when using MD5 is to use the salt value. MD5 is susceptible to brute force attack if salt is not used. Using salt means adding a daily line to the value entered by the user before calculating MD5 and storing it in the database.
For example, if the user-entered value is "ABC" and your salt value is "12345", you will calculate MD5 for "ABC12345".
source share