The TX and RX pins on the Mega are best used for serial debugging, so you’d be better off using one of te other three serial ports on the Mega for your connection to the ESP-01.
Read this for more info (Yes, it’s about connecting a Bluetooth module rather than an ESP-01, but the same issues remain):
You’ll obviously need to amend the sketch that you upload to the Mega (which @Bill_Donnelly has asked you to post, but which you haven’t) .