@Ajal Jose Thanks for reaching out.
Your code looks good to me expect please validate if the values are retrieved correctly or not for the AZURE_MYSQL_USER, AZURE_MYSQL_DATABASE etc. and other values that you have defined.
In case if you have already validated the above then another reason for this error is that the IP address of the client is not authorized to connect to the MySQL server. You can check if the IP address of the client is authorized to connect to the MySQL server by checking the firewall rules of the MySQL server.
Another reason for this error is that the MySQL server is not configured to accept connections over SSL. You can check if the MySQL server is configured to accept connections over SSL by checking the SSL configuration of the MySQL server.
In case if you have already validated it then to know more details on the 500 error you can validate the application insights logs or Diagnose and solve problems blade on your function app to know more details on the error and the steps to mitigate the issue. In you still not able to figure out the reason then please let me know.